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

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Rafal Pietrak <rafal(at)ztk-rp(dot)eu>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: partial JOIN (was: ID column naming convention)
Date: 2015-10-24 13:00:33
Message-ID: CAKFQuwamLXJdfRMrjE-Em57o43N6Tzzs-xiLAJGkBZPE81eptA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, Oct 24, 2015 at 6:41 AM, Rafal Pietrak <rafal(at)ztk-rp(dot)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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Lele Gaifax 2015-10-24 17:56:47 Using function returning multiple values in a select
Previous Message Rafal Pietrak 2015-10-24 10:41:50 partial JOIN (was: ID column naming convention)