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

From Joel Jacobson
Subject Re: Foreign key joins revisited
Date
Msg-id f694514e-1272-435f-ae26-1d53fb940f4d@www.fastmail.com
Whole thread Raw
In response to Re: Foreign key joins revisited  ("Joel Jacobson" <joel@compiler.org>)
Responses Re: Foreign key joins revisited
List pgsql-hackers
On Sun, Dec 26, 2021, at 22:24, Joel Jacobson wrote:
> FROM permission p
>    LEFT JOIN ON KEY p.permission_role_id_fkey r
>    LEFT JOIN team_role tr ON KEY team_role_role_id_fkey TO r
>    LEFT JOIN ON KEY tr.team_role_team_id_fkey t
>    LEFT JOIN user_role ur ON KEY user_role_role_id_fkey TO r
>    LEFT JOIN ON KEY ur.user_role_user_id_fkey u

I think readability can be improved by giving the foreign keys the same names as the referenced tables:

FROM permission p
   LEFT JOIN ON KEY p.role r
   LEFT JOIN team_role tr ON KEY role TO r
   LEFT JOIN ON KEY tr.team t
   LEFT JOIN user_role ur ON KEY role TO r
   LEFT JOIN ON KEY ur.user u

Toughts?

/Joel

pgsql-hackers by date:

Previous
From: Isaac Morland
Date:
Subject: Re: Foreign key joins revisited
Next
From: Sascha Kuhl
Date:
Subject: Re: Foreign key joins revisited