Repository navigation
fix: array lossless extraction, interval, bit(n), JSON round-trip, BC dates (#222) - #223
Merged
Merged
Conversation
… dates (#222) Follow-up to #220/#221 — host-side audit found arrays, intervals, bit(n), JSON round-trips, and BC dates still broken. All fixed: Arrays (issue #222 section 1-2): - Override Kind::Array in extract_value_lossless to route through ArrayValue::from_sql with lossless byte-level element decoders. FLOAT4/FLOAT8 NaN/Infinity, DATE/TIMESTAMP/TIMESTAMPTZ infinity, TIME 24:00:00, NUMERIC wide values, MONEY text, INTERVAL non-normalization, JSON text — all now lossless inside arrays. - Add CAST wrapper for Value::Array when column type is known: CAST(ARRAY[...] AS timestamptz[]) instead of bare ARRAY[...]. Fixes timestamptz[], uuid[], numeric[], date[] insert failures. - Multi-dim arrays fall back to display path (documented limitation). Interval (section 2): - Interval::from_sql no longer normalizes months > 11 to years or hours > 23 to days. Formats as PostgreSQL's interval_out: raw months ("N mons"), days ("N days"), time ("HH:MM:SS.ffffff"). 48 hours stays "48:00:00" (was "2 days"). bit(n) (section 3): - Add char_max_len to BindOptions and ColumnTypeInfo. When base_type is BIT/VARBIT with char_max_len, emit CAST($N AS bit(n)) instead of CAST($N AS bit) (which defaults to bit(1)). JSON/JSONB round-trip (section 4): - extract_simple_kind_lossless returns JsonValue::String(v.to_string()) for JSON/JSONB — serialized JSON text, not bare serde_json::Value. jsonb '"hello"' → "\"hello\"" (round-trips as a JSON string). jsonb 'null' → "null" (distinguishable from SQL NULL). BC dates (section 3): - format_date_with_bc: astronomical year < 0 emits "0044-03-15 BC" (PostgreSQL format) instead of "-0043-03-15" (ISO 8601). Years > 9999 emit without "+" prefix (PostgreSQL doesn't accept it). Trailing -- comment (section 5): - strip_trailing_line_comment: strips trailing -- comment before semicolon trim on the session/cursor path. "select 1 -- c" no longer breaks DECLARE. GUC leak (section 5): - run_one_shot runs RESET ALL after COMMIT/ROLLBACK to clear session-level GUCs set during the transaction. Identity columns (section 5): - is_generated now checks attgenerated <> '' OR attidentity IN ('a', 'd'), catching GENERATED ALWAYS AS IDENTITY columns. ColumnTypeInfo (all): - get_column_types_map returns ColumnTypeInfo { type_name, char_max_len } instead of bare String. Updated all callers (crud.rs, copy.rs, blob.rs). Co-Authored-By: Adam J Esslinger <esslinger@gmail.com>
Version suggestionBased on this PR's title (
This is informational only — no tag or release is created automatically yet. |
get_column_types_map read character_maximum_length as Option<i64>, but information_schema.columns defines it as int (i32), so try_get::<Option<i64>> silently returned None — the bit(n) CAST never received the length and defaulted to bit(1). Fix: read as Option<i32>, cast to i64. Verified bit(3) round-trip against live PostgreSQL over JSON-RPC. Co-Authored-By: Adam J Esslinger <esslinger@gmail.com>
aesslinger
marked this pull request as ready for review
December 2, 2026 21:48
…te wiring (#222) Pre-handoff ensemble review (security + correctness + code-review) found and verified six issues in PR #223's working tree. All fixed here: 1. RESET ALL removed from run_one_shot (copy.rs): it wiped default_transaction_read_only and the app.tabularis_base_search_path GUC on recycled pool connections (Fast recycling doesn't re-run post_create). SET LOCAL is already reverted by COMMIT/ROLLBACK — RESET ALL added nothing and actively harmed the connection. 2. strip_trailing_line_comment rewritten (copy.rs): rfind("--") scanned the whole query (stripping `--` from earlier lines, destroying WHERE clauses); the quote-parity formula `count('\'') - count("''")` undercounted by 1 per `''` pair. Now scans only the last line and uses `count('\'') - 2 * count("''")`. pub(crate) + 7 unit tests added. 3. Interval split into Interval (display, normalized) and PgIntervalText (lossless, non-normalized). The shared struct broke execute_query's display output. PgIntervalText wired into both lossless paths: extract_simple_kind_lossless (scalar) and extract_simple_kind_from_bytes (array/composite elements). Zero-pads hours to match interval_out. 4. BC date suffix placement: format_date_with_bc put " BC" after the date part, but PostgreSQL puts it at the END for timestamp/timestamptz ("0050-03-15 12:30:45 BC", not "0050-03-15 BC 12:30:45"). Split into format_date_with_bc (DATE — BC after date) and format_date_no_bc (timestamp — no suffix, BC appended at end). For timestamptz the offset comes before BC: "0050-03-15 12:30:45+00 BC". 5. Large AD years (≥10000): the lossless path no longer emits the `+` prefix from format_year_chrono — PostgreSQL's date/timestamp input parser rejects "+10000-01-01" ("time zone displacement out of range"). The display path keeps `+` (matches old builtin behavior; not used for round-trips). Verified against live PostgreSQL 16. 6. extract_simple_kind_from_bytes doc comment updated: it no longer covers the "exact same type set" as extract_simple_kind — 9 types now diverge for lossless array/composite elements. README updated: arrays are now lossless (not "stay lossy"), JSON serialized text format, interval non-normalized format documented. Co-Authored-By: Adam J Esslinger <esslinger@gmail.com>
This was referenced Dec 2, 2026
aesslinger
added a commit
that referenced
this pull request
Dec 3, 2026
* fix: BY DEFAULT identity columns must not be is_generated (#224) #223 added `a.attidentity IN ('a', 'd')` to the is_generated check in all four get_columns queries. `attidentity = 'd'` is GENERATED BY DEFAULT AS IDENTITY, which accepts explicit values — only `'a'` (ALWAYS) rejects them. Marking BY-DEFAULT identity columns as is_generated blocked table copy for the common case of a BY-DEFAULT identity primary key. Fix: change `IN ('a', 'd')` to `= 'a'` in all four queries (metadata.rs lines 167, 241, 772, 1404). is_auto_increment stays true for both. Live test: creates a table with all four identity/generated shapes (BY DEFAULT identity PK, ALWAYS identity, stored generated, plain column) and asserts is_generated is present only for ALWAYS identity and stored generated — absent for BY DEFAULT and plain. Co-Authored-By: Adam J Esslinger <esslinger@gmail.com> * test: cover all 4 is_generated query paths for BY DEFAULT identity fix (#224) The ensemble review found 3 of 4 is_generated SQL query sites had zero test coverage for the = 'a' change. Add 3 live tests: 1. get_schema_snapshot_by_default_identity_is_not_generated — exercises fetch_all_columns (line 1404) via get_schema_snapshot; asserts the same 4 identity/generated shapes as the get_columns test. 2. get_view_columns_never_reports_is_generated — exercises get_view_columns (line 772, the COALESCE/LEFT JOIN path); verifies no view column is marked is_generated (views can't have identity/generated columns). 3. get_materialized_view_columns_never_reports_is_generated — exercises fetch_materialized_view_columns (line 241); same assertion for materialized views. All 4 paths now have dedicated live tests. Verified passing against PostgreSQL 16. 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.
Summary
Closes #222 — follow-up to #220/#221. The host re-tested
mainand found arrays, intervals,bit(n), JSON round-trips, and BC dates still broken. All fixed.Arrays (sections 1-2)
Kind::Arrayinextract_value_losslessto route throughArrayValue::from_sqlwith lossless byte-level element decoders. FLOAT4/FLOAT8 NaN/Infinity, DATE/TIMESTAMP/TIMESTAMPTZ infinity, TIME 24:00:00, NUMERIC wide values, MONEY text, INTERVAL non-normalization, JSON text — all now lossless inside arrays.Value::Arraynow wraps inCAST(ARRAY[...] AS timestamptz[])when the column type is known, instead of a bareARRAY[...]literal that PostgreSQL infers astext[]. Fixestimestamptz[],uuid[],numeric[],date[]insert failures.Interval (section 2)
Interval::from_sqlno longer normalizes months > 11 to years or hours > 23 to days. Formats as PostgreSQL'sinterval_out: raw months ("N mons"), days ("N days"), time ("HH:MM:SS.ffffff").48 hoursstays"48:00:00"(was"2 days").bit(n) (section 3)
char_max_lentoBindOptionsandColumnTypeInfo. Whenbase_typeisBIT/VARBITwithchar_max_len, emitsCAST($N AS bit(n))instead ofCAST($N AS bit)(which defaults tobit(1)).JSON/JSONB round-trip (section 4)
extract_simple_kind_losslessreturnsJsonValue::String(v.to_string())for JSON/JSONB — the serialized JSON text, not the bareserde_json::Value.jsonb '"hello"'→"\"hello\""(round-trips as a JSON string).jsonb 'null'→"null"(distinguishable from SQL NULL).BC dates (section 3)
format_date_with_bc: astronomical year < 0 emits"0044-03-15 BC"(PostgreSQL format) instead of"-0043-03-15"(ISO 8601). Years > 9999 emit without+prefix (PostgreSQL doesn't accept it as a year).Trailing
-- comment(section 5)strip_trailing_line_comment: strips trailing-- commentbefore semicolon trim on the session/cursor path."select 1 -- c"no longer breaks DECLARE.GUC leak (section 5)
run_one_shotrunsRESET ALLafterCOMMIT/ROLLBACKto clear session-level GUCs set during the transaction.Identity columns (section 5)
is_generatednow checksattgenerated <> '' OR attidentity IN ('a', 'd'), catchingGENERATED ALWAYS AS IDENTITYcolumns (which haveattgenerated = ''butattidentity = 'a').ColumnTypeInfo
get_column_types_mapreturnsColumnTypeInfo { type_name, char_max_len }instead of bareString. Updated all callers (crud.rs,copy.rs,blob.rs).Test plan
cargo clippy --all-targets -- -D warningsclean.cargo fmt --all --checkclean.Notes
jsonbbig-number precision loss viaf64is a known limitation (needsserde_jsonarbitrary_precisionfeature — deferred).array_outincludes[2:3]={1,2}butVec<Option<T>>::from_sqlnormalizes to[1,2]— deferred).Co-Authored-By: Adam J Esslinger esslinger@gmail.com