public inbox for [email protected]
help / color / mirror / Atom feedFrom: PG Doc comments form <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: Example. Foreign Keys Constraints. Wrong Columns
Date: Tue, 14 Apr 2026 11:08:35 +0000
Message-ID: <[email protected]> (raw)
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)
);
```
view thread (3+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: Example. Foreign Keys Constraints. Wrong Columns
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox