Search Postgresql Archives

Re: partial JOIN (was: ID column naming convention)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Oct 24, 2015 at 6:41 AM, Rafal Pietrak <rafal@xxxxxxxxx> 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.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux