Repository navigation
Description
Summary
#221 closed #220, but several of its items are still broken on main, and a wider sweep of arrays, intervals and bit(n) found more. Everything below was re-run against a release build of main at 7672f6a (the #221 merge) over JSON-RPC against PostgreSQL 16, not taken from the PR description. The host (TabularisDB/tabularis#1625) works around what it can and fails loudly on the rest, so none of this is blocking, but a copy of an affected column fails or is changed.
A lot of #220 is fixed and verified: the duplicate-row rewind (2000 rows now return exactly 2000), NaN/±Infinity/infinity/24:00:00 on scalar reads, money as text, insert_records for inet/cidr/macaddr/xml/varbit/tsvector/point/ranges/money, a BLOB-shaped text value, the query-mismatch error on a reused session_id, ;+whitespace trimming, redacted bind errors, is_generated, full_type, datetime_precision, materialized views and domain types. Thank you. What is left:
1. Still returns null for a value that exists
read_rows returns null with no error, so a caller cannot tell it from SQL NULL. These were in #220 (item 2) and #221 did not cover them.
| Value | Returned |
|---|---|
multi-dimensional array, '{{1,2},{3,4}}'::int[] |
null (the whole cell) |
'null'::jsonb (JSON null) |
null |
'1e400'::jsonb |
null |
time[], array['01:02:03.123456'::time] |
[null] |
float8[] / float4[] containing NaN or Infinity |
[null] |
numeric[] containing NaN |
[null] |
date[], timestamp[] containing infinity |
[null] |
The scalar versions of the float, date, timestamp and time cases are fixed. The same specials inside an array still go through the old display path, so the array element conversion needs the same lossless handling.
2. Returns a changed value
timestamp[]andtimestamptz[]lose precision and offset.array['2024-01-02 03:04:05.123456+00'::timestamptz]reads as['2024-01-02 03:04:05']. The server's text is{"2024-01-02 03:04:05.123456+00"}. The scalar column is fine (2024-06-01 06:30:00+00:00).tstzrangealso drops the offset (["2024-01-01 00:00:00", ...)where the server has+00).intervalis rewritten.interval '48 hours'is stored as48:00:00(a time part, not days) and reads back as2 days. The two compare equal, but they are not the same value: across a DST change'2024-03-09 12:00'::timestamptz + interval '2 days'is2024-03-11 12:00:00-04and+ interval '48 hours'is2024-03-11 13:00:00-04inAmerica/New_York.1000000 hoursreads as41666 days 16:00:00. After a read and an insert, the target's text differs from the source's. The interval needs to be sent in the form PostgreSQL printed it (interval::textgives48:00:00).- Array lower bounds are dropped.
'[2:3]={1,2}'::int[]reads as[1, 2](the server prints[2:3]={1,2}). jsonbnumbers pass throughf64.12345678901234567890123.5reads as1.2345678901234568e+22. fix: close seven read_rows/insert_records copy gaps (#220) #221 lists this as a known limitation (it needsarbitrary_precision).jsonis parsed.{"a":1,"a":2}reads as{"a": 2}.money[]is still integer cents.array[12.5::money]reads as[1250], while scalarmoneyis fixed ('12.50').
3. insert_records cannot write back what read_rows emits
All of these fail loudly and roll the batch back.
bit(n)for anyn > 1:{"v": "101"}intobit(3)fails withbit string length 1 does not match type bit(3).bit(1)works, and so doesvarbit.read_rowsemits'101'. The value is bound with the wrong length (or asbit(1)).- Array columns, JSON array form.
read_rowsemits a JSON array, which works forint4[]but fails fortimestamptz[],timestamp[],date[],uuid[],numeric[],int4range[]andinet[]withcolumn "v" is of type X[] but expression is of type text[], andjsonb[]withUnsupported array element type. A PostgreSQL-literal string ({1.5}) is accepted only forinet[]andint4range[], not fornumeric[],uuid[],date[]or the timestamp arrays. - Composite types:
read_rowsemits{"x": 1, "y": 2};insert_recordsfails withCannot bind a JSON object to a non-JSON column. Acomposite[]reads as an array of objects. - BC dates and large years:
read_rowsemits-0043-03-15(and+5874897-12-31);insert_recordsfails withtime zone displacement out of rangefordate,timestampandtimestamptz.0044-03-15 BCis accepted, but it is not the formread_rowsproduces. (Also in Table copy: rc.15 read_rows repeats rows after a size-budget cut, returns null for NaN/infinity, and insert_records can't write back what read_rows emits #220 item 4.)
4. json/jsonb: the read and write sides do not form a round trip
For a jsonb holding the JSON string "{\"a\":1}", read_rows returns the bare string {"a":1}; for "hello" it returns hello. insert_records treats every string for a json column as JSON text, so a string that happens to be valid JSON comes back as a different type, and any other string fails:
Source jsonb |
read_rows |
After insert_records |
|---|---|---|
"{\"a\":1}" (string) |
'{"a":1}' |
{"a": 1} (object) |
"123" (string) |
'123' |
123 (number) |
"true" (string) |
'true' |
true (boolean) |
"hello" (string) |
'hello' |
fails: invalid input syntax for type json |
null (JSON null) |
null |
becomes SQL NULL |
Sending JSON text for a json column is exact, so a caller can avoid this by selecting col::text (the host does). It is worth documenting that read_rows for json columns is not meant to be fed back, or having read_rows return text for json/jsonb columns.
5. Smaller
-- commenton the session path.select 1 -- cfails withDECLARE cursor failed: syntax error at end of input; the one-shot path accepts it. fix: close seven read_rows/insert_records copy gaps (#220) #221 says trailing comments are trimmed; only;+whitespace is.- GUC leak.
select set_config('probe.leak','yes',false)on the one-shot path leavescurrent_setting('probe.leak')atyesfor the next call on the pooled connection. limit: -1is accepted and becomespage_size: 1000.- Identity columns. A
GENERATED ALWAYS AS IDENTITYcolumn reportsis_auto_increment: truebutis_generatedis not set (is_generatedis correct forGENERATED ALWAYS AS (...) STORED). A caller that skips only generated columns will try to write it.
Suggested fix
Most of section 1, 2 and 3 share one cause: array elements and a handful of scalar types go through the display extractors and the JSON-shape guessing binder rather than the per-type lossless path. Reading every non-simple cell as value::text (and binding by format_type/udt_name from the target column) would remove the need for a case per type.
What the host does meanwhile
SELECTs float, date, time, timestamp, timestamptz and json columns as ::text, and refuses before any write a text value shaped like a blob, JSON it cannot write exactly, and a page the plugin cut short on a pre-fix plugin. Array, range, composite, bit, interval, money, inet, xml and timetz columns are not in the host's supported type list, so a copy of such a column is blocked at plan time with unsupportedSourceType. That keeps the above from corrupting data, but it also means those columns cannot be copied at all until both sides support them. BC dates are the exception: the host reads date, timestamp and timestamptz as ::text, which prints 0044-03-15 BC, and insert_records accepts that form, so only the -0043-03-15 form that a direct read_rows emits (section 3) is affected.
Activity
fix: character_maximum_length is int4 not int8 — fix bit(n) CAST (#222)
fix: ensemble review fixes — RESET ALL, strip comment, interval/BC da…
fix: array lossless extraction, interval, bit(n), JSON round-trip, BC…
chore: release 1.0.0-rc.16 (#228)