Thread: Doc: typo in ddl.sgml
Hi. I noticed that it seems to me a mistake in the sample code in the document. https://www.postgresql.org/docs/devel/ddl-constraints.html#DDL-CONSTRAINTS-FK I think it is a typo for user_id instead of author_id. See bellow. Best reghards, diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml index 898b6dd..c0de169 100644 --- a/doc/src/sgml/ddl.sgml +++ b/doc/src/sgml/ddl.sgml @@ -1269,9 +1269,9 @@ CREATE TABLE users ( CREATE TABLE posts ( tenant_id integer REFERENCES tenants ON DELETE CASCADE, post_id integer NOT NULL, - author_id integer, + user_id integer, PRIMARY KEY (tenant_id, post_id), - FOREIGN KEY (tenant_id, author_id) REFERENCES users ON DELETE SET NULL <emphasis>(author_id)</emphasis> + FOREIGN KEY (tenant_id, user_id) REFERENCES users ON DELETE SET NULL <emphasis>(user_id)</emphasis> ); </programlisting> Without the specification of the column, the foreign key would also set
On Wednesday, November 6, 2024, kasaharatt <kasaharatt@oss.nttdata.com> wrote:.
I noticed that it seems to me a mistake in the sample code in the document.
https://www.postgresql.org/docs/devel/ddl-constraints.html# DDL-CONSTRAINTS-FK
I think it is a typo for user_id instead of author_id.
It’s hard to argue a typo when three different places need to be changed, and the example is fully functional as-is.
The example writer intentionally chose to make author_id the FK of the PK user_id column in order to reduce ambiguity as to which column is on the FK table and which is on the PK table. And to emphasize that the columns need not be named the same in any case.
David J.
Hi, thanks for your comment. > On Wednesday, November 6, 2024, kasaharatt > <kasaharatt@oss.nttdata.com> wrote:. > >> I noticed that it seems to me a mistake in the sample code in the >> document. >> > https://www.postgresql.org/docs/devel/ddl-constraints.html#DDL-CONSTRAINTS-FK >> [1] >> >> I think it is a typo for user_id instead of author_id. > > It’s hard to argue a typo when three different places need to be > changed, and the example is fully functional as-is. Yeah, you are right. I mistakenly thought it was syntactically incorrect. The sample code works correctly. Best regards,