-
Notifications
You must be signed in to change notification settings - Fork 4.1k
sql/pg_catalog: emit a NOT NULL row in pg_constraint for each NOT NULL column (PG18 compat) #169937
Copy link
Copy link
Open
Labels
A-sql-pgcatalogA-sql-pgcompatSemantic compatibility with PostgreSQLSemantic compatibility with PostgreSQLA-sql-vtablesVirtual tables - pg_catalog, information_schema etcVirtual tables - pg_catalog, information_schema etcA-tools-pgdumpIssues relating to pg_dump compatibilityIssues relating to pg_dump compatibilityC-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.O-agentFiled by an AI agent; usually the result of a human/agent investigation sessionFiled by an AI agent; usually the result of a human/agent investigation sessionT-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Metadata
Metadata
Assignees
Labels
A-sql-pgcatalogA-sql-pgcompatSemantic compatibility with PostgreSQLSemantic compatibility with PostgreSQLA-sql-vtablesVirtual tables - pg_catalog, information_schema etcVirtual tables - pg_catalog, information_schema etcA-tools-pgdumpIssues relating to pg_dump compatibilityIssues relating to pg_dump compatibilityC-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.O-agentFiled by an AI agent; usually the result of a human/agent investigation sessionFiled by an AI agent; usually the result of a human/agent investigation sessionT-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Describe the problem
PostgreSQL 18 changed
pg_catalog.pg_constraintto expose a row withcontype = 'n'for every column-levelNOT NULLconstraint. CockroachDBstill follows pre-18 behavior and emits no row in
pg_constraintforcolumn
NOT NULLconstraints, only forPRIMARY KEY,UNIQUE,FOREIGN KEY, andCHECK.This breaks tools, ORMs, and applications that target PG18 and expect to
discover
NOT NULLconstraints by queryingpg_constraint.This is the catalog-visibility piece of the broader PG18 NOT-NULL rework
tracked in #168988 (which also covers naming,
NOT VALID,NO INHERIT,and the
attnullabilityfield). This issue is scoped to just thepg_catalog.pg_constraintsurface — the change most directly visible toclient tooling.
To Reproduce
PostgreSQL 18.3:
CockroachDB (master, v26.3.0-alpha):
Expected behavior
For each non-nullable column,
pg_constraintshould contain a row with:contype = 'n'conname = '<table>_<column>_not_null'(when no explicit name has been given)conkey = {<column ordinal>}pg_get_constraintdef(oid) = 'NOT NULL <column>'conrelidset to the table OID,contypid = 0Code references
populateTableConstraintsiteratestable.AllConstraints()but emits norow for
NOT NULLcolumn constraints:pkg/sql/pg_catalog.go:1188-1401conTypeNotNull = "n"constant already exists and is used today onlyfor domain-level NOT NULL:
pkg/sql/pg_catalog.go:1153,pkg/sql/pg_catalog.go:1466information_schema.table_constraintsalready synthesizes these rows(as
CHECK, matching PG's information_schema mapping) by walkingtable.PublicColumns(). That walk is a useful template for thepg_constraintchange:pkg/sql/information_schema.go:1503-1516pg_get_constraintdefwill need a corresponding case for'n':pkg/sql/sem/builtins/pg_builtins.go:861Notes
constraints,
NOT VALID,NO INHERIT, theattnullabilityrework,and
ALTER TABLE … ALTER CONSTRAINT … [NO] INHERITsyntax remaintracked in sql/schema: track NOT NULL as proper table constraints (PG18 compatibility) #168988.
rows.
oidHasheralready has helpers for other constraint kinds; anew
NotNullConstraintOid(db, schema, table, column)helper would fitthe existing pattern.
clusters may not expect the new rows.
Environment:
Additional context
PG release notes: "Store column NOT NULL specifications in pg_constraint".
PG commit: a379061a22a8.
Related: #168988 (broader PG18 NOT-NULL rework).
Epic CRDB-39727
Jira issue: CRDB-63721