Skip to content

[BUG] 5.4-SNAPSHOT: PostgreSQL 18 CREATE TABLE declarative partitions cannot be parsed #2522

Description

@minleejae

Failing SQL feature

PostgreSQL declarative partitioning is not represented by CreateTable:

  • A multi-column parent PARTITION BY fails at the comma.
  • CREATE TABLE ... PARTITION OF fails at OF for RANGE, LIST, HASH, and DEFAULT bounds.

SQL examples

CREATE TABLE pg_range_parent (
    tenant_id int,
    happened_at timestamptz
) PARTITION BY RANGE (tenant_id, happened_at);

CREATE TABLE pg_range_p1 PARTITION OF pg_range_parent
    FOR VALUES FROM (1, MINVALUE) TO (2, MAXVALUE);

CREATE TABLE pg_list_parent (region text) PARTITION BY LIST (region);
CREATE TABLE pg_list_eu_us PARTITION OF pg_list_parent
    FOR VALUES IN ('eu', 'us');
CREATE TABLE pg_list_default PARTITION OF pg_list_parent DEFAULT;

CREATE TABLE pg_hash_parent (tenant_id int) PARTITION BY HASH (tenant_id);
CREATE TABLE pg_hash_p0 PARTITION OF pg_hash_parent
    FOR VALUES WITH (MODULUS 4, REMAINDER 0);

Actual behavior

Tested with JSqlParser 5.4-SNAPSHOT at 9a32ff568f580178d9a27b101596aa43eb45d0b7:

  • The multi-column parent throws ParseException at the comma in (tenant_id, happened_at).
  • Every PARTITION OF form throws ParseException at OF.

Expected behavior

These statements should parse as CreateTable, deparse without losing partition clauses, and expose structured fields for:

  • partition strategy and ordered partition keys;
  • the parent table of a partition;
  • RANGE FROM/TO, LIST IN, HASH MODULUS/REMAINDER, and DEFAULT bounds.

Software information and server validation

  • JSqlParser: 5.4-SNAPSHOT
  • Database: PostgreSQL 18.6 (postgres:18)
  • All seven statements above executed successfully with ON_ERROR_STOP=1. pg_inherits, pg_get_partkeydef, and pg_get_expr(relpartbound, ...) confirmed the resulting parent/child partition metadata.
  • Grammar reference: https://www.postgresql.org/docs/18/sql-createtable.html

AI assistance

OpenAI Codex was used to assemble the syntax matrix and run the parser/server comparison. The cases were checked against the PostgreSQL 18 documentation and an actual PostgreSQL 18.6 server.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions