Re: Foreign key joins revisited

From: "Joel Jacobson" <joel(at)compiler(dot)org>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Foreign key joins revisited
Date: 2021-12-26 21:38:25
Message-ID: f694514e-1272-435f-ae26-1d53fb940f4d@www.fastmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Sascha Kuhl 2021-12-26 21:39:45 Re: Foreign key joins revisited
Previous Message Isaac Morland 2021-12-26 21:36:41 Re: Foreign key joins revisited