drizzle-team / drizzle-team/drizzle-orm-docs
Docs: PostgreSQL generated columns can be used in PK/UNIQUE/FK (non-partitioned tables)
- Dominant language
- MDX
- Stars
- 241
- Forks
- 401
- Avg merge
- 5h 44m
- Merged PRs (30d)
- 1
Description
Doc Location: https://orm.drizzle.team/docs/generated-columns (PostgreSQL)
## Problem:
Under limitations section, the page incorrectly says: “Cannot directly use in primary keys, foreign keys or unique constraints.”
In PostgreSQL, stored generated columns can be indexed and can serve as PRIMARY KEY (with NOT NULL) or **UNIQUE`, and can be referenced by foreign keys. The known limit is that a generated column cannot be a partition key.
## Minimum proof of SQL:
```SQL
CREATE TABLE t (
x int NOT NULL,
y int GENERATED ALWAYS AS (x * 2) STORED NOT NULL,
PRIMARY KEY (y) -- OK
);
CREATE TABLE child (
y_ref int REFERENCES t(y) -- OK: FK references generated PK
);
```
Also note that "VIRTUAL" is now available in PostgreSQL 18.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.