pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

PARTITION OF create path: support child-specific column elements

Open tianzhou opened this issue 5 months ago • 0 comments

Context

PR #498 (issue #496) changed the create path for partition children from standalone CREATE TABLE to CREATE TABLE ... PARTITION OF ... FOR VALUES .... This correctly attaches children to their parent and handles child-specific constraints (via conparentid = 0 filtering).

Gap

PostgreSQL's PARTITION OF grammar accepts a full OptTypedTableElementList, which includes column-level elements beyond table constraints:

CREATE TABLE child PARTITION OF parent (
    col1 WITH OPTIONS DEFAULT 42,     -- per-child default override
    col2 WITH OPTIONS NOT NULL        -- per-child NOT NULL override
) FOR VALUES IN ('value');

The current PARTITION OF branch in generateTableSQL only serializes child-specific table constraints. It does not emit per-child column-level overrides (defaults, identity, generated expressions, storage parameters).

Impact

Low — per-child column overrides on partition children are uncommon in practice. The parent's column definitions are inherited automatically, and most schemas don't override them per-child.

Proposed fix

If the IR shows a child column with a different default/identity/generated expression than the parent column, emit it as a WITH OPTIONS element in the PARTITION OF statement.

Related: #496, PR #498

tianzhou avatar Jul 03 '26 06:07 tianzhou