| From: | PG Doc comments form <noreply(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-docs(at)lists(dot)postgresql(dot)org |
| Cc: | postgresql(dot)org(dot)reach457(at)passmail(dot)net |
| Subject: | Example. Foreign Keys Constraints. Wrong Columns |
| Date: | 2026-04-14 11:08:35 |
| Message-ID: | 177616491576.403057.11334419722719232554@wrigleys.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-docs |
The following documentation comment has been logged on the website:
Page: https://www.postgresql.org/docs/18/ddl-constraints.html
Description:
https://www.postgresql.org/docs/current/ddl-constraints.html#DDL-CONSTRAINTS-FK
In the last example of this section it seems the `users` table is referenced
wrong.
```sql
CREATE TABLE users (
tenant_id integer REFERENCES tenants ON DELETE CASCADE,
user_id integer NOT NULL,
PRIMARY KEY (tenant_id, user_id)
);
CREATE TABLE posts (
tenant_id integer REFERENCES tenants ON DELETE CASCADE,
post_id integer NOT NULL,
author_id integer,
PRIMARY KEY (tenant_id, post_id),
FOREIGN KEY (tenant_id, author_id) REFERENCES users ON DELETE SET NULL
(author_id)
);
```
In this example `FOREIGN KEY (tenant_id, author_id) REFERENCES users ON
DELETE SET NULL (author_id)` implies that `users` table columns are named
`(tenant_id, author_id)` but in fact `users` table does not have a
`author_id` column.
That line should be probably like this because `users` tables has a
`user_id` column instead of `author_id`
```sql
CREATE TABLE posts (
# ...
FOREIGN KEY (tenant_id, author_id) REFERENCES users (tenant_id, user_id)
ON DELETE SET NULL (author_id)
);
```
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Yushu Chen | 2026-04-15 09:45:41 | Re: doc: Clarify ANALYZE VERBOSE output |
| Previous Message | David G. Johnston | 2026-04-13 22:28:28 | Re: doc: Clarify ANALYZE VERBOSE output |