Skip to content

feat: model PostgreSQL temporal key and foreign key constraints - #2697

Merged
manticore-projects merged 2 commits into
JSQLParser:masterfrom
minleejae:feat/pg18-temporal-constraints
Sep 24, 2026
Merged

manticore-projects merged 2 commits into
JSQLParser:masterfrom
minleejae:feat/pg18-temporal-constraints

Conversation

@minleejae

Copy link
Copy Markdown
Contributor

PostgreSQL 18 adds temporal PRIMARY KEY/UNIQUE constraints with WITHOUT OVERLAPS and foreign keys with PERIOD. These forms currently fail to parse, preventing schema tools from reading temporal table definitions.

Add explicit temporal markers to index-column metadata and the foreign-key reference model. PRIMARY KEY and UNIQUE share the existing index-key parser; both sides of a foreign key share a column-list parser that enforces the final-column position of PERIOD. CREATE TABLE and ALTER TABLE ADD reuse these paths. The legacy referenced-column-name list keeps bare names and remains mutable.

Execution comparison also exposed a related ALTER UNIQUE bug: named PostgreSQL constraints lost their names on output. Reusing NamedConstraint preserves the name for both ordinary and temporal UNIQUE constraints.

Validation:

  • Full Gradle check with Java 17, including grammar ambiguity and static analysis.
  • AST/mutation and round-trip tests cover PRIMARY KEY, UNIQUE/NULLS NOT DISTINCT, INCLUDE/deferrability, explicit/omitted referenced columns, quoted identifiers, ordinary period identifiers, statement boundaries, and malformed marker placement.
  • Twelve PostgreSQL 18.6 execution cases compare original, toString(), and deparser SQL, including constraint names and temporal catalog flags. Behavior checks verify overlap rejection and a child range covered jointly by adjacent parent ranges.
  • Six referential-action combinations rejected by PostgreSQL 18.6 are recorded as semantic boundaries. The parser represents the syntax; it does not validate range types, operator classes, or all server-specific action restrictions.

Use Dialect.POSTGRESQL for the PostgreSQL ALTER constraint paths. Reference: PostgreSQL 18 CREATE TABLE.

Signed-off-by: minleejae <mmj9808@gmail.com>
@manticore-projects

Copy link
Copy Markdown
Contributor

Please resolve conflicts

Signed-off-by: minleejae <mmj9808@gmail.com>
@manticore-projects
manticore-projects merged commit dac8159 into JSQLParser:master Sep 24, 2026
7 of 8 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