Re: Foreign key joins revisited

Поиск
Список
Период
Сортировка
От Joel Jacobson
Тема Re: Foreign key joins revisited
Дата
Msg-id b75b532e-000f-41e4-8253-37b36402bffd@www.fastmail.com
обсуждение исходный текст
Ответ на Re: Foreign key joins revisited  (Corey Huinker <corey.huinker@gmail.com>)
Ответы Re: Foreign key joins revisited  (Isaac Morland <isaac.morland@gmail.com>)
Re: Foreign key joins revisited  (Corey Huinker <corey.huinker@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Teodor Sigaev
Дата:
Сообщение: CREATE TABLE ( .. STORAGE ..)
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Add Boolean node