Re: partial JOIN (was: ID column naming convention) - Mailing list pgsql-general

From David G. Johnston
Subject Re: partial JOIN (was: ID column naming convention)
Date
Msg-id CAKFQuwamLXJdfRMrjE-Em57o43N6Tzzs-xiLAJGkBZPE81eptA@mail.gmail.com
Whole thread Raw
In response to partial JOIN (was: ID column naming convention)  (Rafal Pietrak <rafal@ztk-rp.eu>)
Responses Re: partial JOIN (was: ID column naming convention)  (Rafal Pietrak <rafal@ztk-rp.eu>)
List pgsql-general
On Sat, Oct 24, 2015 at 6:41 AM, Rafal Pietrak <rafal@ztk-rp.eu> wrote:
The only way I know to avoid the column name
duplication is to explicity select column list:
SELECT s.sled,s.length,s....,r.runner as right,r.length as
right_length,r....,l.runner as left,l.length as left_length,l.* FROM
sleds s JOIN runners l ON (s.left=l.runner) JOIN runners r ON
(s.right=r.runner);
.... which is truely overtalkative (and thus obfuscates future query
analize during code maintenance).

​Skimmed...​

​Using explicit column names is expected - using "*" in non-trivial and production queries is not.

You can move the aliases if you would like.

SELECT *
FROM tablea (col1, col2, col4)
JOIN tableb AS tb1 (col1, col3, col5) USING (col1)
JOIN tableb AS tb2​
 
​(col1, col6, col7) USING (col1)

The "USING" clause ensure that only a single "col1" appears in the output.

For all other columns in the duplicate join you need to provide a context-specific alias.​

David J.

pgsql-general by date:

Previous
From: Rafal Pietrak
Date:
Subject: partial JOIN (was: ID column naming convention)
Next
From: Lele Gaifax
Date:
Subject: Using function returning multiple values in a select