Skip to content

docs(pg): correct generated-column limitations per issue #608#690

Open
sanjibani wants to merge 1 commit into
drizzle-team:mainfrom
sanjibani:docs/fix-pg-generated-columns-limitations
Open

docs(pg): correct generated-column limitations per issue #608#690
sanjibani wants to merge 1 commit into
drizzle-team:mainfrom
sanjibani:docs/fix-pg-generated-columns-limitations

Conversation

@sanjibani

Copy link
Copy Markdown

The PostgreSQL generated-columns page lists "Cannot directly use in primary keys, foreign keys, or unique constraints" as a limitation. That is incorrect for stored generated columns: they can be used in PK, FK, and UNIQUE constraints as long as the column is NOT NULL. The known limit is that a generated column cannot be a partition key.

Fixes #608.

Verified against the PostgreSQL 17 docs (https://www.postgresql.org/docs/current/ddl-generated-columns.html) and a minimal repro (PR description in #608):

CREATE TABLE t (
  x int NOT NULL,
  y int GENERATED ALWAYS AS (x * 2) STORED NOT NULL,
  PRIMARY KEY (y)
);

CREATE TABLE child (
  y_ref int REFERENCES t(y)
);

Both CREATE TABLE statements succeed. The old limitation is removed; the partition-key limit is the only remaining constraint worth calling out at the same level.

Scope: 1 line in 1 file. The cockroach-generated-columns page has the same line, but Cockroach's behavior is not the topic of #608 — leaving the cockroach copy alone to keep the change scoped.

No em-dash.

…#608

Signed-off-by: sanjibani <18418553+sanjibani@users.noreply.github.com>
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.

Docs: PostgreSQL generated columns can be used in PK/UNIQUE/FK (non-partitioned tables)

1 participant