Re: Foreign key joins revisited - Mailing list pgsql-hackers

From Joel Jacobson
Subject Re: Foreign key joins revisited
Date
Msg-id b75b532e-000f-41e4-8253-37b36402bffd@www.fastmail.com
Whole thread Raw
In response to Re: Foreign key joins revisited  (Corey Huinker <corey.huinker@gmail.com>)
Responses Re: Foreign key joins revisited
Re: Foreign key joins revisited
List pgsql-hackers
On Sun, Dec 26, 2021, at 23:25, Corey Huinker wrote:
> My second guess would be:
> FROM permission p
> LEFT JOIN role AS r ON [FOREIGN] KEY [(p.col1 [, p.col2 ...])]
>
> where the key spec is only required when there are multiple foreign keys in permission pointing to role.
>
> But my first guess would be that the standards group won't get around to it.

It's a quite nice idea. It would definitively mean an improvement, compared to today's SQL.

Benefits:
* Ability to assert the join is actually performed on foreign key columns.
* Conciser thanks to not always having to specify all key columns on both sides.

However, I see one problem with leaving out the key columns:
First, there is only one FK in permission pointing to role, and we write a query leaving out the key columns.
Then, another different FK in permission pointing to role is later added, and our old query is suddenly in trouble.

/Joel

pgsql-hackers by date:

Previous
From: Teodor Sigaev
Date:
Subject: CREATE TABLE ( .. STORAGE ..)
Next
From: Peter Eisentraut
Date:
Subject: Add Boolean node