Thread: duplicate columns with COPY

duplicate columns with COPY

From
Peter Eisentraut
Date:
Is there a reason why COPY TO STDOUT does not allow columns to be specified 
more than once?

pei=# copy test1 (a, a) to stdout;
ERROR:  42701: column "a" specified more than once

Or is this just an overly extensive check that is actually intended for COPY 
FROM STDIN?

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/


Re: duplicate columns with COPY

From
Andrew Dunstan
Date:

Peter Eisentraut wrote:
> Is there a reason why COPY TO STDOUT does not allow columns to be specified 
> more than once?
>
> pei=# copy test1 (a, a) to stdout;
> ERROR:  42701: column "a" specified more than once
>
> Or is this just an overly extensive check that is actually intended for COPY 
> FROM STDIN?
>
>   

You should be able to get around it with:
 COPY (SELECT a , a FROM  test1) TO stdout;

cheers

andew


Re: duplicate columns with COPY

From
NikhilS
Date:
Hi,
>
> pei=# copy test1 (a, a) to stdout;
> ERROR:  42701: column "a" specified more than once
>
> Or is this just an overly extensive check that is actually intended for COPY
> FROM STDIN?
>
>

This seems to be a common check in both "COPY TO" and "COPY FROM" cases source/destination being STDIN or otherwise. While it definitely makes sense for the FROM case maybe we could relax this for the COPY TO case.

Regards,
Nikhils
--
EnterpriseDB               http://www.enterprisedb.com

Re: duplicate columns with COPY

From
Tom Lane
Date:
Peter Eisentraut <peter_e@gmx.net> writes:
> Is there a reason why COPY TO STDOUT does not allow columns to be specified 
> more than once?

> pei=# copy test1 (a, a) to stdout;
> ERROR:  42701: column "a" specified more than once

> Or is this just an overly extensive check that is actually intended for COPY 
> FROM STDIN?

I think it's reasonable even for COPY TO, since IMHO the odds that it's
a typo, rather than intentional, are probably 100:1.

As already noted, we do have a workaround if that is truly what you
intend.
        regards, tom lane


Re: duplicate columns with COPY

From
Peter Eisentraut
Date:
Am Donnerstag, 20. Dezember 2007 schrieb Tom Lane:
> I think it's reasonable even for COPY TO, since IMHO the odds that it's
> a typo, rather than intentional, are probably 100:1.

ISTM that with this line of argument we could disable thousands of valid uses 
of SQL commands.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/