Skip to content

fix: parse compound expressions in array constructors - #2672

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/postgresql-array-elements
Sep 21, 2026
Merged

manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/postgresql-array-elements

Conversation

@minleejae

Copy link
Copy Markdown
Contributor

Valid PostgreSQL input such as ARRAY['a', (1 + 0)::text] fails because a short syntactic lookahead cannot see through the parenthesized arithmetic expression and chooses the nested-array fallback. A bare nested array beginning with a parenthesized element can also be mistaken for a function call.

Parse every array element through a shared ArrayElement production, reusing the existing expression and range paths for the first and subsequent elements. Dispatch bare array constructors by their opening bracket and exclude that token from both the function-name probe and its cache eligibility guard. The existing ArrayConstructor AST and visitor APIs are unchanged.

Regression tests cover both expression-parser modes, first/middle/last positions, arithmetic and casts, CASE, scalar subqueries, NULL, row constructors, multidimensional arrays, AST mutation and visitor/table traversal. Existing bare/typed array, range and subscript forms retain coverage. Type compatibility and rectangular dimensions remain database checks.

Syntax reference: PostgreSQL array constructors.

Validation:

  • PostgreSQL 17.11: 33 cases, 89 executions, all verified. The 25 valid cases produced matching results for the original SQL, toString() output and StatementDeParser output. Five malformed inputs were rejected by the server; three additional type/dimension errors were rejected for all three output forms. Regressions include SELECT, INSERT, UPDATE and a JSON path-deletion expression using an array operand.
  • Full Java 17 Gradle check passed, including grammar ambiguity, formatting, Checkstyle, PMD, SpotBugs, coverage and 8006 JUnit tests (0 failures/errors, 25 skipped).

Signed-off-by: minleejae <mmj9808@gmail.com>
@manticore-projects
manticore-projects merged commit fafeb79 into JSQLParser:master Sep 21, 2026
10 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you!

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.

2 participants