Repository navigation
Type native Postgres trees as PostgreSQL 18.6 does, and drop follow-on findings - #153
Merged
Merged
Conversation
The Postgres typing rules now resolve `||` on arrays, jsonb, bytea and other non-string types through pg_operator, give lower and upper of a range or multirange its element type, read hexadecimal, octal, binary and underscore-separated integer literals, keep the precision of current_time, current_timestamp, localtime and localtimestamp, collapse nested array casts to one array type, and drop the typmod from polymorphic results such as lag and lead. Casts to pseudo-types and unknown, and polymorphic calls whose arguments do not agree, are left untyped instead of guessed. The engine-type replay now runs through the native PostgreSQL parser as well as the shared one, over the expression matrix and over every accepted query-shaped syntax case. Each replay fails on any wrong type and on any rise in the untyped count. scripts/record_postgres_types.py --syntax-cases records the second fixture from a postgres:18.6 container.
Under the Postgres profile, a CTE whose body has a finding, or that reads a CTE that does, is faulted. Column references checked against a faulted CTE's columns are not reported, because they repeat the root finding. The root finding, unknown qualifiers and findings against other relations are still reported. Other profiles are unchanged.
A derived table in FROM whose body has a finding, or reads a faulted CTE, is faulted like a CTE, so column references checked against its columns are not reported again. The root finding and findings against other relations are still reported.
Single-line doc comments, explicit parse results, a named helper for the faulted-CTE lookup, a per-case loop in the native typing test and a named constant for the accepted-case marker. No behaviour changes.
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.
Postgres typing from native trees, checked against PostgreSQL 18.6, plus narrow follow-on suppression for Postgres name findings. Snowflake and DuckDB behaviour is unchanged.
Typing
Under the Postgres profile, typing now:
||on arrays (array || array, array || element), jsonb, bytea and other non-string types throughpg_operator;lower/upperof a range or multirange its element type;0x,0o,0band_-separated integer literals;current_time(p),current_timestamp(p),localtime(p)andlocaltimestamp(p);integer[][]) to one array type;lagandlead.Where the exact type isn't certain, typing abstains (untyped) and doesn't guess. That covers casts to pseudo-types and
unknown, polymorphic calls whose arguments disagree or include untyped literals, and||between an untyped literal and an array.Each change has a case in
given_a_native_postgres_tree_when_typing_outputs_then_types_follow_postgresql_18_6. All 15 cases fail on main. Every expected type was recorded from a postgres:18.6 view column.Engine-type replay through the native parser
given_engine_recorded_postgres_types_when_typing_outputs_then_none_is_wrongnow also replays through the native PostgreSQL parser. Each replay fails on any wrong type and on any rise in the untyped count.On main, the native figures are 1,343 / 2 / 22 and 662 / 31 / 276. The 276 untyped include 43 queries the native parser on main can't read whole. They span 15 SQL/JSON and SQL/XML forms, and the pending Postgres parser work already reads them.
The new fixture
postgres_syntax_types.jsoncomes frompython scripts/record_postgres_types.py --container <pg18.6> --docker '<docker>' --syntax-cases. Re-recording the existing matrix fixture with the changed script reproduces it byte for byte.Test-only dependency: sqlquack-semantics gains a
[dev-dependencies]entry on sqlquack-syntax-postgres, for the native replay. Its normal dependencies don't change.Follow-on name findings (Postgres profile only)
A CTE, or a derived table in FROM, is faulted when its body has a finding or it reads a faulted CTE. Column references checked against a faulted relation's columns (E201, E221) are not reported, because they repeat the root finding. The root finding, unknown qualifiers (E222) and findings against other relations are still reported. The test covers:
The test fails without the change.
Proof on the exact head
Gate on the exact head
5e9722ee088a7c77098926a24fe99423602b670fagainst main12b3c6f8d(its base), each step run once:make check-cimake test-rustsnapshot.jsondiffers only incatalogue_commit,translation.erronly in the binary path; exit codes identical[]sqlquack verifywith recorded results, libduckdb loadedsyntax-coverage results --againstmain's baselineresults-baseline.jsonunchangedThe Postgres coverage figure is unchanged: 1,384 of 1,555 forms, 19,346 of 22,726 obligations, 0 problems.