From: | Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com> |
---|---|
To: | Andrus <kobruleht2(at)hot(dot)ee> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: How to disable duplicate columns |
Date: | 2007-04-09 21:39:59 |
Message-ID: | 20070409143139.K29851@megazone.bigpanda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Sun, 8 Apr 2007, Andrus wrote:
> I have tables with large number of columns some of which are duplicate.
> I need to use
>
> SELECT t1.*, t2.* FROM t1 join t2 using (t)
>
> since I don't know all column names of t1 and t2 tables at design time.
>
> In this case PostgreSQL returns table with duplicate columns.
> How to force Postgres to return only first table column when second table
> contains column with same name?
There are a few cases where duplicate columns are trimmed, such as select
* from something with a join ... using or natural join only should result
in one output column for the joined upon column names.
> Code to reproduce:
>
> create table t1 ( id integer
> /*, a lot of other columns */ );
> create table t2 ( id integer
> /*, a lot of other columns */ );
> create table t3 as select t1.*,t2.* from t1 join t2 using (id);
If only id were duplicated, then select * from t1 join t2 using(id)
should work. If other columns are duplicated, then that won't work, but
generally just choosing the first column with a name seems bizarre in that
case.
From | Date | Subject | |
---|---|---|---|
Next Message | Leon Mergen | 2007-04-09 21:46:50 | INSERT..RETURNING on partitioned table |
Previous Message | Lorenzo Thurman | 2007-04-09 21:30:07 | Re: NEWBIE: How do I get the oldest date contained in 3 tables |