public inbox for [email protected]
help / color / mirror / Atom feedFrom: Yushu Chen <[email protected]>
To: David G. Johnston <[email protected]>
To: [email protected]
To: [email protected]
Subject: Re: Example. Foreign Keys Constraints. Wrong Columns
Date: Fri, 17 Apr 2026 23:06:28 +0800
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAKFQuwbm4BD49A8ZqjZnxHKW8MsEURa6hrEvAWKxw0_nu=FZwg@mail.gmail.com>
References: <[email protected]>
<CAKFQuwbm4BD49A8ZqjZnxHKW8MsEURa6hrEvAWKxw0_nu=FZwg@mail.gmail.com>
David G. Johnston wrote:
> On Wed, Apr 15, 2026 at 7:51 AM PG Doc comments form <[email protected]>
> wrote:
>
>> 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
>>
>>
> Given that users has:
>
>> PRIMARY KEY (tenant_id, user_id)
>>
>>
> This:
>
>
>> FOREIGN KEY (tenant_id, author_id) REFERENCES users ON DELETE SET NULL
>> (author_id)
>>
>>
> And this:
>
>
>> FOREIGN KEY (tenant_id, author_id) REFERENCES users (tenant_id,
>> user_id)
>> ON DELETE SET NULL (author_id)
>>
>
> Produce an identical outcome.
>
> The absence of a column list on the former causes the system to look at the
> primary key for the named table and use its column list - which is
> (tenant_id, user_id), same as the later explicit version.
>
> David J.
>
Thanks for explanation.
I think "columns mapping" (just how I call it in this example) makes
this example slightly non-intuitive, and reflects a less-common use case.
Would it help to change `author_id` to `user_id` as a more
straightforward case?
Yushu Chen
view thread (3+ messages)
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], [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