Skip to content

Model PostgreSQL ON COMMIT, access method and DROP behavior - #2814

Open
minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:feat/postgresql-table-options-20261014
Open

minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:feat/postgresql-table-options-20261014

Conversation

@minleejae

@minleejae minleejae commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

PostgreSQL temporary-table and access method clauses parse today, but each word becomes its own table option. A caller that wants the ON COMMIT action of CREATE TEMP TABLE t (a INT) ON COMMIT DELETE ROWS has to reassemble four raw options. ALTER TABLE … DROP [COLUMN] c RESTRICT fails, while the same statement with CASCADE parses.

Current design (As-is)

  • CreateTableOption has typed alternatives for WITH (…), WITHOUT OIDS and the MySQL options. Other clauses fall back to CreateParameter, so each token becomes a Kind.OTHER option:
    • ON COMMIT DELETE ROWS: 4 options (ON, COMMIT, DELETE, ROWS);
    • ON COMMIT DROP: 3 options;
    • USING heap: 2 options, also in CREATE TABLE … USING heap AS SELECT ….
  • The ALTER TABLE DROP forms keep CASCADE/RESTRICT as raw strings in getParameters(). The column form accepts only CASCADE (and Oracle's CASCADE CONSTRAINTS).

Target design (To-be)

  • ON COMMIT: one option of the new TableOption.Kind.ON_COMMIT.
    • The new TableOption.OnCommitAction enum holds PRESERVE_ROWS, DELETE_ROWS and DROP. It also holds Oracle's private temporary table actions PRESERVE_DEFINITION and DROP_DEFINITION, which were accepted as raw tokens before.
    • getOnCommitAction()/setOnCommitAction() and the TableOption.onCommit(action) factory follow the replacement rules of Make table option state transitions explicit #2765: raw tokens discard the action, and the setter replaces the option's contents.
  • USING method: one option of the new Kind.ACCESS_METHOD, with name USING and the method as its value.
    • The value is a String, as in CreateView.getAccessMethod() and ALTER TABLE … SET ACCESS METHOD.
    • It applies to CREATE TABLE … AS and, with Dialect.POSTGRESQL, after PARTITION BY.
    • New factory TableOption.accessMethod(name).
  • Grammar:
    • Two alternatives with explicit lookahead in CreateTableOption, and a new OnCommitTableOption() production next to it.
    • No new tokens or reserved words. PRESERVE and DEFINITION are matched as contextual keywords.
    • USING INDEX TABLESPACE stays a raw option.
    • Incomplete clauses such as ON COMMIT and ON COMMIT DELETE are now rejected.
  • ALTER TABLE DROP behavior: AlterExpressionDrop.getBehavior() returns the shared CascadeBehavior (Consolidate CASCADE/RESTRICT enums (breaking API change) #2745).
    • It covers the column, CONSTRAINT, PRIMARY KEY, UNIQUE (…) and FOREIGN KEY (…) drop forms, so every DROP action in the class uses the same field. The grammar reuses the existing CASCADE | RESTRICT production.
    • Oracle's CASCADE CONSTRAINTS and INVALIDATE remain raw parameters, and their order is preserved.
  • Compatibility:
    • CreateTable.getTableOptionsStrings() and TableOption.getTokens() return the same word tokens as before (ON, COMMIT, DELETE, ROWS; USING, heap). SQL output is unchanged.
    • Code that scanned Kind.OTHER options for these words now finds one typed option instead.
    • AlterExpressionDrop.getParameters() still ends with CASCADE or RESTRICT. When a behavior is set, it returns a read-only snapshot; change the clause with setBehavior.
  • usage.rst documents the new kinds and the DROP behavior.

Validation

  • 38 new tests:
    • PostgreSqlTableOptionsTest (18):
      • parse, toString, deparser and reparse with Dialect.POSTGRESQL and without a dialect, plus statement boundaries;
      • AST fields and the legacy tokens, clause order, and CREATE TABLE … AS;
      • the Oracle forms, USING INDEX TABLESPACE and rejected ON COMMIT forms;
      • edits, state transitions and the factories.
    • AlterDropBehaviorTest (20):
      • RESTRICT/CASCADE on column and constraint drops, with and without COLUMN/IF EXISTS;
      • multiple actions and legacy getParameters();
      • Oracle raw clauses, edits and rejected repeated behaviors.
  • Java 17 offline Gradle spotlessApply check: 10,392 tests, 10,367 passed, 25 skipped, zero failures/errors. The grammar choice conflict check passes.
  • Compared with master (bdf8ac31) on a corpus of 635 MySQL 8.4 and PostgreSQL 18 DDL/DCL statements, each accepted by the server, plus variants:
    • Fixed: ALTER TABLE … DROP a, DROP COLUMN b RESTRICT (with Dialect.POSTGRESQL and without a dialect) and two DROP [COLUMN] … RESTRICT variants. 0 regressions; no other case changed status or statement class.
    • AST changes:
      • ON COMMIT DROP, USING heap and ON COMMIT DELETE ROWS now hold one typed option each, with identical tableOptionsStrings.
      • Three DROP … CASCADE actions move CASCADE from the raw parameter list to behavior; getParameters() is unchanged.
  • MySQL 8.4 and PostgreSQL 18.3: every corpus statement this branch parses ran as written on one server and as rendered by toString() on a second, identical server, in the same order. All 205 MySQL and 329 PostgreSQL statements give the same result (success, or the same error).

Integration validation

Applied #2806–#2819 together on master (bdf8ac31), with the stacked PRs on top of their bases (#2806 → #2807 → #2808, #2806 → #2809 → #2810 and #2811 → #2812).

  • Each branch merges cleanly into master. Between the branches, conflicts are limited to adjacent additions (README/index rows, usage sections, imports, visitor and feature lists, one enum line and one alias guard).
  • The integrated build passes Java 17 offline Gradle spotlessApply check: 11,494 tests, 11,469 passed, 25 skipped, zero failures/errors. The grammar choice conflict check passes.
  • On a corpus of 635 MySQL 8.4 and PostgreSQL 18 DDL/DCL statements, each accepted by the server, the integrated build parses 265 of 271 MySQL statements (master: 206) and 363 of 364 PostgreSQL statements (master: 328). Every MySQL 8.4 non-reserved word and PostgreSQL 18 unreserved or column-name keyword parses as a column and table name.
  • On paired MySQL 8.4 and PostgreSQL 18.3 servers, all 263 MySQL and 362 PostgreSQL statements rendered by the integrated build give the same results as the originals.

CREATE TABLE ON COMMIT and USING clauses were split into one raw
TableOption per word. Parse them as Kind.ON_COMMIT with a typed
OnCommitAction and as Kind.ACCESS_METHOD; the legacy token lists and
SQL output are unchanged.

ALTER TABLE DROP [COLUMN] c RESTRICT was rejected. AlterExpressionDrop
now keeps CASCADE/RESTRICT as a CascadeBehavior for column and
constraint drops, and getParameters() still lists the keyword.

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

This branch has not been deployed

No deployments
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