duplicate columns with COPY

Started by Peter Eisentrautabout 18 years ago5 messages
#1Peter Eisentraut
peter_e@gmx.net

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/

#2Andrew Dunstan
andrew@dunslane.net
In reply to: Peter Eisentraut (#1)
Re: duplicate columns with COPY

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

#3NikhilS
nikkhils@gmail.com
In reply to: Andrew Dunstan (#2)
Re: duplicate columns with COPY

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

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#1)
Re: duplicate columns with COPY

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

#5Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#4)
Re: duplicate columns with COPY

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/