From: Rob Sargent <robjsargent@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: distinguishing identical columns after joins
Date: Tue, 01 Mar 2011 12:53:38 -0700
Message-ID: <4D6D4EC2.70306@gmail.com> (raw)
In-Reply-To: <AANLkTinSR8Wuago7HdATetEiXQLU8fjbnm2tX5n1RGHG@mail.gmail.com>
References: <AANLkTinSR8Wuago7HdATetEiXQLU8fjbnm2tX5n1RGHG@mail.gmail.com>
On 03/01/2011 12:47 PM, S G wrote:
> This question is particularly geared towards self-joins, but can apply
> to any join where the tables involved have any identical column names.
> Aside from explicit column references, is there any way to pull all
> columns (*) from each table in a join and quickly append/prepend some
> identifier to distinguish them from each other? For example, table t1
> contains columns named col1 and col2:
>
> SELECT
> *
> FROM
> t1 AS a
> INNER JOIN
> t1 AS b
> ON
> a.col1 = b.col1
>
> would yield a result set with column names: col1, col2, col1, col2.
> I'm looking for something that would automatically rename the columns
> like: a_col1, a_col2, b_col1, b_col2. Does such functionality exist?
> It's not such a big deal in this example, but it can be quite tedious
> to explicitly reference and rename every single column for such joins
> when the tables involved have a very large number of columns.
>
> I would beg for the same functionality when expanding compound
> datatypes. For example, a compound datatype cd1 exists with fields
> named f1 and f2:
>
> SELECT
> ((value1, value2)::cd1).* AS a
>
> normally produces a result set with column names: f1, f2. I'm looking
> for something that would produce column names: a_f1, a_f2.
>
> Thanks!
> sg
>
select a.col1 as a_col1 etc doesn't do it for you?
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: robjsargent@gmail.com
Subject: Re: distinguishing identical columns after joins
In-Reply-To: <4D6D4EC2.70306@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox