| From: | Yushu Chen <gentcys(at)gmail(dot)com> |
|---|---|
| To: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, postgresql(dot)org(dot)reach457(at)passmail(dot)net, pgsql-docs(at)lists(dot)postgresql(dot)org |
| Subject: | Re: Example. Foreign Keys Constraints. Wrong Columns |
| Date: | 2026-04-17 15:06:28 |
| Message-ID: | 793f2989-6bb1-4a9f-b882-545a44539566@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-docs |
David G. Johnston wrote:
> On Wed, Apr 15, 2026 at 7:51 AM PG Doc comments form <noreply(at)postgresql(dot)org>
> 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
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | vignesh C | 2026-04-17 05:32:16 | Re: Logical Replication upgrade |