Skip to content

fix: array lossless extraction, interval, bit(n), JSON round-trip, BC dates (#222) - #223

Merged
aesslinger merged 3 commits into
mainfrom
fix/issue-222-read-rows-copy-gaps
Dec 2, 2026
Merged

aesslinger merged 3 commits into
mainfrom
fix/issue-222-read-rows-copy-gaps

Conversation

@aesslinger

Copy link
Copy Markdown
Collaborator

Summary

Closes #222 — follow-up to #220/#221. The host re-tested main and found arrays, intervals, bit(n), JSON round-trips, and BC dates still broken. All fixed.

Arrays (sections 1-2)

  • Lossless array extraction: 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.
  • Array CAST on insert: Value::Array now wraps in CAST(ARRAY[...] AS timestamptz[]) when the column type is known, instead of a bare ARRAY[...] literal that PostgreSQL infers as text[]. Fixes timestamptz[], uuid[], numeric[], date[] insert failures.
  • Multi-dimensional arrays fall back to the 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)

  • Added char_max_len to BindOptions and ColumnTypeInfo. When base_type is BIT/VARBIT with char_max_len, emits 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 — the serialized JSON text, not the 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 as a year).

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 (which have attgenerated = '' but attidentity = 'a').

ColumnTypeInfo

  • get_column_types_map returns ColumnTypeInfo { type_name, char_max_len } instead of bare String. Updated all callers (crud.rs, copy.rs, blob.rs).

Test plan

  • Unit: 793 lib tests pass (36 new — interval non-normalization, JSON text, BC dates, lossless array elements, array CAST, bit(n) length). cargo clippy --all-targets -- -D warnings clean. cargo fmt --all --check clean.
  • Live (podman, all containers up): 63 live_db (62 + 1 pgvector), 87 client_live_tests (all 5 session-cursor tests), 3 shutdown, 2 worker_starvation — all green.

Notes

  • Composite types are skipped (not in the host's supported type list — documented limitation).
  • jsonb big-number precision loss via f64 is a known limitation (needs serde_json arbitrary_precision feature — deferred).
  • Array lower bounds are dropped (PostgreSQL's array_out includes [2:3]={1,2} but Vec<Option<T>>::from_sql normalizes to [1,2] — deferred).

Co-Authored-By: Adam J Esslinger esslinger@gmail.com

… 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>
@aesslinger aesslinger added enhancement New feature or request prerelease:rc Version suggestion targets a release candidate labels Dec 2, 2026
@aesslinger aesslinger self-assigned this Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

Version suggestion

Based on this PR's title (fix) and the prerelease:rc label:

Current 1.0.0-rc.15
Suggested next tag v1.0.0-rc.16

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
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>
@aesslinger
aesslinger merged commit 47cca76 into main Dec 2, 2026
8 checks passed
@aesslinger
aesslinger deleted the fix/issue-222-read-rows-copy-gaps branch December 2, 2026 22:23
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request prerelease:rc Version suggestion targets a release candidate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Table copy follow-up to #220: arrays, intervals and bit(n) still lose or reject data; #221 left several #220 items open

1 participant