Skip to content

fix: read PostgreSQL function-call index elements without a dialect - #2967

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/index-function-elements-default-20261201
Dec 2, 2026
Merged

manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/index-function-elements-default-20261201

Conversation

@minleejae

Copy link
Copy Markdown
Contributor

PostgreSQL index elements may be function calls without extra parentheses, as in CREATE INDEX ix ON t (lower(label)) or EXCLUDE USING gist (lower(label) WITH =). With Dialect.POSTGRESQL they are read as expressions. Without a dialect, a function call became a column named after the function, with its arguments as a text parameter: lower with (label), printed as lower (label). CAST(...), EXTRACT(...), schema-qualified functions and functions with expression arguments, such as int4range(n, n + 1), were parse errors.

This change reads these elements with Dialect.POSTGRESQL and without a dialect, never with another dialect, through the existing CastExpression, ExtractExpression and Function branches of IndexColumnWithParams. CREATE INDEX and EXCLUDE constraints in CREATE TABLE and ALTER TABLE get the same KeyElement expressions as with the dialect.

Without a dialect, a name followed by one integer in parentheses stays a MySQL key-part prefix length, as in KEY k (label(10)). PostgreSQL reads label(10) as a function call, and so does Dialect.POSTGRESQL. isMySqlKeyPartPrefixAhead() keeps the prefix reading.

Compatibility: without a dialect, a function-call key element is now a KeyElement with an expression instead of a column name with parameters, and is printed without the inserted space (lower(label)). Statements that were parse errors now parse. MySQL, Oracle and the other dialects are unchanged. Without a dialect, the trailing parameter list still absorbs tokens after an element, as for n + 1 before. This now also applies after CAST(...) and EXTRACT(...). PostgreSQL rejects these forms, and so does Dialect.POSTGRESQL.

Reference: PostgreSQL 18 CREATE INDEX ("the parentheses can be omitted if the expression has the form of a function call"), CREATE TABLE (exclude_element).

Validation

  • PostgreSqlDdlKeyOptionsTest: 8 statements parse without a dialect, round-trip, and give the same key element types as with Dialect.POSTGRESQL. They cover lower(label) with operator class, order and NULLS LAST, coalesce, date_trunc, CAST, EXTRACT, a schema-qualified function with COLLATE, int4range(n, n + 1), and EXCLUDE in CREATE TABLE and ALTER TABLE. A prefix length stays a column without a dialect and with MySQL and Oracle, while Dialect.POSTGRESQL reads a function. MySQL keeps its reading of lower(label) and still rejects CAST(...). The 8 statements fail on the base (2ba80d35c).
  • PostgreSQL 18.3 accepted every statement in the tests. label(10) is reported as a missing function label(integer), not a syntax error. The two bare expressions mentioned above are syntax errors.
  • Java 17 gradle check (Spotless, Checkstyle, PMD, JaCoCo verification): 16,848 tests, 0 failures, 25 skipped.

AI assistance: prepared with Claude Code.

@manticore-projects

Copy link
Copy Markdown
Contributor

Please resolve conflicts.

Signed-off-by: minleejae <mmj9808@gmail.com>
@minleejae
minleejae force-pushed the fix/index-function-elements-default-20261201 branch from f5a60b2 to bd5d8c3 Compare December 2, 2026 07:40
@manticore-projects
manticore-projects merged commit e7f18f7 into JSQLParser:master Dec 2, 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