Skip to content

feat(schema): model LIKE and PARTITION OF tables and partition links - #67

Merged
omer-cengel merged 1 commit into
masterfrom
feature/model-like-and-partition-of-tables
Oct 10, 2026
Merged

omer-cengel merged 1 commit into
masterfrom
feature/model-like-and-partition-of-tables

Conversation

@omer-cengel

Copy link
Copy Markdown
Member

Summary

Schema sources that create tables with CREATE TABLE ... (LIKE t ...) or CREATE TABLE ... PARTITION OF t previously produced tables with missing columns or failed internally. sqlcj now copies the source table's columns, keeps partitions in step with their parent, and rejects the CREATE TABLE forms whose columns it cannot determine, so a table is never modeled with missing columns.

Changes

  • LIKE t, with any INCLUDING/EXCLUDING options, copies the columns, types, and nullability of the modeled table t at its position in the element list, beside column definitions, table constraints, or further LIKE clauses, in written order. A repeated column name fails as Column already exists in table <t>: <c>.
  • PARTITION OF t with FOR VALUES FROM ... TO, IN, WITH (MODULUS ...), or DEFAULT, and an optional table-constraint list, starts with its parent's columns.
  • Neither form copies the source's constraints. A missing source fails as Table not found in schema: <t>.
  • () is modeled as a table without columns.
  • AS SELECT, OF <type>, and INHERITS are rejected as Unsupported CREATE TABLE clause: <clause> at line <n>. A CREATE TABLE with no element list, (), or PARTITION OF is rejected as unsupported table DDL.
  • A partition follows its parent: ADD, DROP, and RENAME COLUMN, ALTER COLUMN ... TYPE, and SET/DROP NOT NULL reach partitions recursively. Renaming the parent keeps the link.
  • DROP TABLE of a parent removes its partitions recursively. Every name of one DROP TABLE is resolved before anything is dropped, so DROP TABLE parent, partition loads.
  • ATTACH PARTITION of a modeled table starts the link and DETACH PARTITION ends it. A partition sqlcj does not model is still ignored. A LIKE copy never follows its source.
  • A LIKE or PARTITION OF source, or an ATTACH/DETACH PARTITION partition, resolves by its unqualified name, so public.t is t. The same name qualified with any other schema fails as Table not found in schema: <schema>.<t>.
  • The PostgreSQL documentation describes these constructs, the propagation rules, the new diagnostics, and the tests that verify them.

Scope and non-goals

  • The source's constraints and defaults are not copied, and no generated code reads them.
  • Table inheritance and ALTER TABLE ... INHERIT are not modeled. Schemas other than public are not modeled beyond the qualified-name rule above.
  • Column options after PARTITION OF or OF <type> and AS SELECT ... WITH NO DATA cannot be read by the SQL parser and stay rejected as unreadable table DDL.
  • Combinations PostgreSQL rejects, such as a column definition after PARTITION OF, are not validated.
  • Generated code does not change.

CREATE TABLE copies the columns of a modeled LIKE source or partition
parent in written order, models () as a table without columns, and
rejects AS SELECT, OF type, and INHERITS with their line. A partition
follows its parent's column changes, rename, and DROP TABLE until
DETACH PARTITION, and ATTACH PARTITION of a modeled table links it.
@omer-cengel
omer-cengel merged commit ec8360a into master Oct 10, 2026
7 checks passed
@omer-cengel
omer-cengel deleted the feature/model-like-and-partition-of-tables branch October 10, 2026 18:04
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