Repository navigation
fix: read non-native copy columns as server text, close remaining copy gaps - #227
Merged
Merged
Conversation
…y gaps (#225) read_rows now projects every column that is not a native JSON type through ::text inside the read transaction (money via ::numeric::text), so values are the server's own output instead of hand-written binary decoders. This closes multi-dimensional arrays, array lower bounds, 1e400 and wide jsonb numbers, json duplicate keys, tstzrange offsets and interval normalization in one mechanism, and deletes the lossless decoders that kept diverging. Column metadata comes from prepare, so a zero-row result reports its columns. - one-shot reads always ROLLBACK, so set_config(..., false) cannot leak into the pooled connection - trailing comments and semicolons are trimmed with the pagination lexer, fixing `select 1 -- c\n` on the session path - a negative or non-integer limit is a -32602 error, not 1000 - insert_records casts otherwise-unrecognized values to the column's qualified type (composites, lower-bound arrays) and accepts objects in jsonb[] arrays Co-Authored-By: Adam J Esslinger <esslinger@gmail.com>
insert_records turned a text value like '[1,2,3]' into the array
literal {1,2,3} whatever the target column, so a copied text cell
holding a JSON array arrived changed. Skip the array guess when the
column is a known text-family type; array and unknown columns keep it.
Co-Authored-By: Adam J Esslinger <esslinger@gmail.com>
- a bytea column takes only the BLOB wire format; any other string (an unresolved BLOB_FILE_REF, corrupt base64) is an error again instead of being cast to bytea and stored as its own text - behind a transaction pooler read_rows runs on a one-shot connection and starts with DEALLOCATE ALL, so its prepare can't collide with statement names another client left on the backend (42P05) - hstore text from read_rows casts to the column's hstore type - the JSON-array guess applies only to array or unknown columns, so a user-defined range's [a,b] text reaches the cast to its type - the read also pins bytea_output = 'hex' and TimeZone = 'UTC' - raw SQL, WKT and UUID shape guesses no longer apply to text columns, so an md5 hash in a text column is copied as is - stale docs, a split doc comment, and tests for the settings, session columns on later pages, a trailing ';', a failed first page, row editing of a composite and the pooler collision Co-Authored-By: Adam J Esslinger <esslinger@gmail.com>
aesslinger
added a commit
that referenced
this pull request
Dec 3, 2026
Bumps version to 1.0.0-rc.16 in .tabularium, Cargo.toml, Cargo.lock, and the CHANGELOG. This release includes manual commit mode (#219), the read_rows server-text read path (#225, #227), and the copy fixes from #220/#221, #222/#223 and #224/#226. Known limitations: money[] locale text form and composite types named like built-ins.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #225
Why a different approach
#220 → #222 → #225 were three rounds of the same bug class. tokio-postgres always asks for binary results, so every
read_rowsvalue came from a hand-written Rust copy of a PostgreSQL output function (array_out,interval_out,jsonb_out,range_out, BC dates…). Each retest found the next mismatch, for exampleinterval '14 months'(PostgreSQL normalizes months to years but never hours to days). This PR stops imitating the server and lets it produce the text.Read side
Inside the read transaction,
read_rowscallsprepareto get the column metadata. It then wraps the query asSELECT c1, c2::text, … FROM (\n<query>\n) AS tabularis_q(c1..cN):"NaN"/"Infinity"), bytea (full base64), text/varchar/bpchar/name, uuid::numeric::text, so it stays"123.45"::textThe transaction pins
DateStyle='ISO, MDY',IntervalStyle='postgres'andextra_float_digits=3withSET LOCAL.This one change closes:
[2:3]=lower bounds1e400, wide jsonb numbers and json duplicate keyststzrangeoffsetsThe lossless binary decoders are deleted: PgNumeric, the full temporal decoders, PgIntervalText, PgMoneyText and the lossless array decoder.
extract.rsnow differs from rc.15 only inextract_value_lossless.Smaller items
ROLLBACK. The transaction is read-only, so there is nothing to commit, andROLLBACKreverts anyset_config(…, false)the query issued, which fixes the GUC leak. The startup script's settings are applied beforeBEGIN, so they survive.;are trimmed with the pagination lexer (trim_statement_end), replacing the hand-rolledstrip_trailing_line_comment.select 1 -- c\nnow works on the session path, and user SQL is always placed on its own lines inside the wrapping parens.limit: -1(or any non-integer) now returns-32602instead of the default 1000.Write side
CAST($N AS <udt_schema>.<udt_name>), cast to the column's qualified type. This fixes composites and lower-bound arrays. Text-family columns are never cast, and the BLOB decode is still bytea-only.jsonb[]array are written as quoted JSON text.'[1,2,3]') going into a known text-family column is stored as is. It used to be rewritten to{1,2,3}, a bug that predates this PR and was found in the host retest. Array and unknown columns keep the array conversion.Review fixes (ensemble review + host retest)
BLOB:wire format. Any other string, such as an unresolvedBLOB_FILE_REF:from the file picker or corrupt base64, is an error again. Before this fix, the new cast step stored the string's own bytes.read_rowsruns on a one-shot connection and starts withDEALLOCATE ALL, so its describepreparecan't collide with statement names left on the pooler's backend (42P05).read_rowsreturns for an hstore column is cast back to hstore on write.[1.5,2.5]reaches the cast to its type.bytea_output='hex'andTimeZone='UTC'.;, a failed first page, composite row editing, and the pooler collision.Not changed:
money[]keeps the server's locale form (documented), and user types named like built-ins still get cast to the built-in type, which predates this PR.Contract changes (host)
timestamptzis read in UTC (+00).intervalfollowsIntervalStyle=postgres.columns.postgres_plugin_table_copypasses 3/3 against the release build.Verification
-D warningsand fmt are clean.read_rows_returns_the_servers_text_for_every_non_native_typecovers every Table copy follow-up to #222: multi-dimensional arrays, jsonb 1e400, session-path comment newline, GUC leak, jsonb[]/composite inserts #225/Table copy follow-up to #220: arrays, intervals and bit(n) still lose or reject data; #221 left several #220 items open #222 shape:read_rowsvalues equalcol::texton both the one-shot and session pathsinsert_recordsinto a clone table, then checks that anEXCEPTof the two tables'::textrows is empty-- copy\n, and a zero-row read must still report its columnsread_rows_one_shot_does_not_leak_session_gucsfails under COMMIT (red confirmed) and passes with ROLLBACK.