Skip to content

fix: read array_in's dimension decoration and nested empty arrays in value sets - #186

Merged
CaffeinatedCoder merged 3 commits into
mainfrom
fix/array-dimension-decoration
Oct 18, 2026
Merged

CaffeinatedCoder merged 3 commits into
mainfrom
fix/array-dimension-decoration

Conversation

@CaffeinatedCoder

@CaffeinatedCoder CaffeinatedCoder commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

Closes #128

Problem

Value set literals threw FormatException on two forms PostgreSQL's array_in reads as one-dimensional arrays:

  • The dimension decoration, [lower:upper]= or [upper]=. array_out prints it whenever the lower bound isn't 1, so the library couldn't read back a column another tool wrote as '[0:1]={1,2}'.
  • Nested empty arrays, such as {{}} and {{},{}}.

Change

  • SetFormat.Parse (src/CodoMetis.ValueRanges/Internals/SetFormat.cs) now reads the decoration and drops it, since a set has no index. Every value set type and every entry point goes through it. The rule was measured on PostgreSQL 16 and 18, which agree on every decoration row:
    • each bound is an optionally signed decimal int4, with no whitespace inside the brackets;
    • upper + 1 must not overflow, so [2147483647:2147483647] fails;
    • whitespace may surround the =;
    • the element count as written, duplicates included, must equal upper - lower + 1, so [1:1]={1,1} fails and [1:2]={1,1} is {1};
    • a decoration needs at least one element, so [1:0]={} and [1:1]={{}} fail;
    • a second bracket pair is a second dimension, which a set still rejects.
  • Nested empty arrays read as {} when they are regular (same depth throughout): {{}}, {{},{}}, { {} }, {{{}},{{}}}. Mixed depths such as {{},{{}}} fail, as on the server.
  • Docs: two "Good to know" bullets in docs/value-sets.md#parse-and-print-literals (claim S20). The CHANGELOG entry is under 10.0.0 → Fixed.

The version split, confirmed by the 10.0.0 assessment session. PostgreSQL 16 rejects {{}} and its variants, while 17 and 18 read them as {}. The sets follow 17 and later. This is safe because the library binds values, never this text, and the server never prints {{}}, so only input you write yourself (a literal, JSON, a query string, the TypeConverter) reaches it. docs/value-sets.md names both versions (claim S21). {{1}} and every other multi-dimensional form still fail. Also measured: PostgreSQL 16 rejects a vertical tab before { and 18 accepts it. The parser follows 18, as the existing whitespace rule already does.

Tests

  • SetDimensionDecorationTests (core): 55 literals measured with pg_input_is_valid on 16 and 18, plus every family. With the fix reverted, 23 fail (all 22 accepted rows and the every-family test). The 33 rejection rows pass either way; they guard against loosening too far.
  • LiteralGrammarParityTests.NestedEmptyArrays_ReadAsPostgres17AndLaterReadThem_AndPostgres16Rejects asks PostgreSQL 16, 17 and 18 directly; 16 and 18 run in containers of the test's own. It fails if either side of the split moves, or if a nested array holding an element stops being two-dimensional. I made it fail both ways: without the library's nested-empty reading, and with the expectation moved to 16.
  • LiteralCorpusProbeTests (live PostgreSQL 17, all 28 value set types) gains the accepted and malformed edges. Its 28 Value set literals refuse array_in's dimension decoration ([1:1]={…}) and {{}} #128 candidates now report "candidate fixed" and are removed. LiteralGrammarParityTests still passes.
  • Core 1081, NodaTime 196, conventions 324, EF unit 251 + 81, ASP.NET Core 84: all passed.

🤖 Generated with Claude Code

…value sets

Value set literals threw on two forms PostgreSQL reads as one-dimensional arrays: the decoration
`[lower:upper]=` (or `[upper]=`), which array_out prints whenever the lower bound is not 1, so a
column written as '[0:1]={1,2}' could not be read back; and empty arrays nested to one depth,
`{{}}` and `{{},{}}`. SetFormat.Parse now reads the decoration and drops it, as PostgreSQL 16 and 18
do (they agree): signed decimal int4 bounds with no whitespace inside the brackets, upper + 1
representable, whitespace around '=', and the element count as written, duplicates included, equal
to upper - lower + 1. A second bracket pair is a second dimension and still refused. The nested
empties read as {} as PostgreSQL 17 and 18 do; PostgreSQL 16 refuses them, which the docs say.

SetDimensionDecorationTests holds the measured table (22 accepted rows fail with the fix reverted;
the 33 refusals pass either way). LiteralCorpusProbeTests gains the edges for all 28 value set
types; its 28 #128 candidates are removed as fixed.

Closes #128

Found-By: OT
Defect-Class: LIT

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 10.0.0 milestone Oct 18, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working found-by/oracle Found by the generated-oracle machinery (claims × API surfaces) area/value-sets Value set families and wrapper arities area/literals Parse, TryParse and formatting package/core Affects CodoMetis.ValueRanges severity/low Cosmetic, message or documentation-level difference labels Oct 18, 2026
CaffeinatedCoder and others added 2 commits October 18, 2026 18:25
The sets read {{}} as {} as PostgreSQL 17 and 18 do, and docs/value-sets.md says 16 rejects it.
LiteralGrammarParityTests now asks each version (the suite's 17, and its own 16 and 18 containers),
so the test fails when either side of the split moves rather than the sentence going stale; a
nested array holding an element stays two-dimensional everywhere and rejected here. Claim S21
holds the sentence.

Shown to fail both ways: without the library's nested-empty reading ("Int32Set does not read {{}}
as {}"), and with the expectation moved to 16 ("PostgreSQL 16 rejects {{}}").

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	CHANGELOG.md
#	test/oracles/candidates.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/literals Parse, TryParse and formatting area/value-sets Value set families and wrapper arities bug Something isn't working found-by/oracle Found by the generated-oracle machinery (claims × API surfaces) package/core Affects CodoMetis.ValueRanges severity/low Cosmetic, message or documentation-level difference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Value set literals refuse array_in's dimension decoration ([1:1]={…}) and {{}}

1 participant