Skip to content

fix: preserve PostgreSQL quoted names, numeric scales and comment literals - #2638

Open
minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:fix/postgresql-syntax-coverage
Open

minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:fix/postgresql-syntax-coverage

Conversation

@minleejae

Copy link
Copy Markdown
Contributor

PostgreSQL quoted identifiers such as "a.b" are currently split again while constructing table and column AST nodes. For example, DROP INDEX "a.b" reports "b" as its name and invents schema "a". Numeric types with negative scales fail in type fragments, DDL and casts, and COMMENT rejects escape strings containing an escaped quote and newline-separated ordinary string literals.

This change preserves lexer-separated name components with Dialect.POSTGRESQL, including table-name copies. It accepts negative numeric scales through the shared type grammar, preserves precision/scale metadata for qualified types, and distinguishes scale -1 from an omitted scale. ColDataType.fromNumericParameters supports nullable parameters while preserving the existing primitive constructor's sentinel behavior.

COMMENT and SELECT share character-literal parsing. PostgreSQL E'...' enables escapes for that literal, and newline concatenation accepts ordinary quoted continuations while rejecting dollar-quoted continuations. Tagged dollar comments already work in 5.4 with the PostgreSQL preset; the existing default-off behavior is retained and covered by regression tests. Default and BigQuery dotted-name behavior is also retained.

Validation:

  • Added 75 parameterized/regression tests covering quoted object and column names, clone/resolved-table names, numeric aliases and boundaries, arrays, DDL/casts, dollar tags and bodies, E strings, literal continuation, malformed input and dialect isolation.
  • Gradle check: 6,979 tests, no failures/errors, 25 skipped; formatting, static analysis and grammar ambiguity checks passed.
  • Maven clean verify: 6,961 tests, no failures/errors, 25 skipped.
  • Differential audit against PostgreSQL 18.6 and both the 5.4 release and master 6312f9e5: 253 selected cases, 237 accepted by PostgreSQL. AST/deparse checks improve from 93 to 229 passing cases, with no regressions among previously passing valid cases. All 229 regenerated valid SQL cases execute successfully on PostgreSQL.

The remaining eight valid audit failures are unsupported COMMENT target kinds (INDEX, SCHEMA, SEQUENCE, DOMAIN, TYPE, MATERIALIZED VIEW, FUNCTION, CONSTRAINT), which require an extension of the Comment target AST. PostgreSQL precision/scale range validation is left to the database.

Syntax references: numeric types, lexical structure, COMMENT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant