Re: [HACKERS] \copy (query) delimiter syntax error

Lists: pgsql-hackerspgsql-patches
From: Michael Fuhr <mike(at)fuhr(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Subject: \copy (query) delimiter syntax error
Date: 2007-02-03 09:18:05
Message-ID: 20070203091805.GA59938@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

psql's \copy (query) with a delimiter yields a syntax error:

test=> \copy foo to foo.txt delimiter '|'
(works)

test=> \copy (select * from foo) to foo.txt
(works)

test=> \copy (select * from foo) to foo.txt delimiter '|'
ERROR: syntax error at or near "USING"
LINE 1: COPY ( select * from foo ) TO STDOUT USING DELIMITERS '|'

The problem is that \copy sends USING DELIMITERS for backward
compatibility (comment on line 502 of src/bin/psql/copy.c) but that
COPY (query) doesn't support USING DELIMITERS:

CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
copy_from copy_file_name copy_delimiter opt_with copy_opt_list
...
| COPY select_with_parens TO copy_file_name opt_with
copy_opt_list

copy_delimiter:
/* USING DELIMITERS kept for backward compatibility. 2002-06-15 */
opt_using DELIMITERS Sconst

What should be fixed -- COPY or \copy? Does psql's \copy still
need backward compatibility to unsupported pre-7.3?

--
Michael Fuhr


From: "Andrew Dunstan" <andrew(at)dunslane(dot)net>
To: "Michael Fuhr" <mike(at)fuhr(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: \copy (query) delimiter syntax error
Date: 2007-02-03 16:52:29
Message-ID: 63462.24.211.165.134.1170521549.squirrel@www.dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Michael Fuhr wrote:
> psql's \copy (query) with a delimiter yields a syntax error:
>
> test=> \copy foo to foo.txt delimiter '|'
> (works)
>
> test=> \copy (select * from foo) to foo.txt
> (works)
>
> test=> \copy (select * from foo) to foo.txt delimiter '|'
> ERROR: syntax error at or near "USING"
> LINE 1: COPY ( select * from foo ) TO STDOUT USING DELIMITERS '|'
>
> The problem is that \copy sends USING DELIMITERS for backward
> compatibility (comment on line 502 of src/bin/psql/copy.c) but that
> COPY (query) doesn't support USING DELIMITERS:
>
> CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
> copy_from copy_file_name copy_delimiter opt_with
> copy_opt_list
> ...
> | COPY select_with_parens TO copy_file_name opt_with
> copy_opt_list
>
> copy_delimiter:
> /* USING DELIMITERS kept for backward compatibility.
> 2002-06-15 */
> opt_using DELIMITERS Sconst
>
> What should be fixed -- COPY or \copy? Does psql's \copy still
> need backward compatibility to unsupported pre-7.3?
>

I'd say fix psql. Not sure how far back we should backpatch it. It's
interesting that this has been there since 8.0 and is only now discovered.

cheers

andrew


From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: \copy (query) delimiter syntax error
Date: 2007-02-03 17:12:07
Message-ID: 20070203171207.GA89295@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Sat, Feb 03, 2007 at 10:52:29AM -0600, Andrew Dunstan wrote:
> I'd say fix psql. Not sure how far back we should backpatch it. It's
> interesting that this has been there since 8.0 and is only now discovered.

The problem is new in 8.2 because COPY (query) doesn't support USING
DELIMITERS. COPY tablename does, so it has worked all along.

--
Michael Fuhr


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org, "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] \copy (query) delimiter syntax error
Date: 2007-02-03 19:54:24
Message-ID: 45C4E870.8080202@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Michael Fuhr wrote:
> On Sat, Feb 03, 2007 at 10:52:29AM -0600, Andrew Dunstan wrote:
>
>> I'd say fix psql. Not sure how far back we should backpatch it. It's
>> interesting that this has been there since 8.0 and is only now discovered.
>>
>
> The problem is new in 8.2 because COPY (query) doesn't support USING
> DELIMITERS. COPY tablename does, so it has worked all along.
>
>

oh, good point. OK, I have cut this quick patch that will continue to
accept the legacy syntax in psql in non-inline-query cases, but will
make psql unreservedly emit new style syntax for COPY to the backend.
Does that seem reasonable, or is it too much of a change for the stable
branch?

cheers

andrew

Attachment Content-Type Size
copy.patch text/x-patch 3.9 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Michael Fuhr <mike(at)fuhr(dot)org>, pgsql-hackers(at)postgresql(dot)org, "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] \copy (query) delimiter syntax error
Date: 2007-02-04 17:38:40
Message-ID: 20127.1170610720@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> oh, good point. OK, I have cut this quick patch that will continue to
> accept the legacy syntax in psql in non-inline-query cases, but will
> make psql unreservedly emit new style syntax for COPY to the backend.
> Does that seem reasonable, or is it too much of a change for the stable
> branch?

We've never promised that psql's backslash commands would work at all
with older backends, so I think removing compatibility with pre-7.3
backends at this point isn't a problem. OTOH, going out of your way
to remove compatibility seems a bit pointless, so I'd vote against the
"have_query" parts of this patch. Just change the output format.

regards, tom lane


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Michael Fuhr <mike(at)fuhr(dot)org>, pgsql-hackers(at)postgresql(dot)org, "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] \copy (query) delimiter syntax error
Date: 2007-02-04 21:18:19
Message-ID: 3964.1170623899@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> The consequence will be, though, that psql will accept a syntax for
> "\copy (query) ..." that the corresponding backend command would reject
> were we not transforming it. That strikes me as potentially confusing.

Perhaps. What about plan B: remove the legacy syntax support in \copy?
IIRC it has not been documented since 7.2, so maybe we can finally throw
it overboard. Thoughts?

regards, tom lane


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Michael Fuhr <mike(at)fuhr(dot)org>, pgsql-hackers(at)postgresql(dot)org, "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] \copy (query) delimiter syntax error
Date: 2007-02-04 21:20:25
Message-ID: 45C64E19.4080000@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
>
>> oh, good point. OK, I have cut this quick patch that will continue to
>> accept the legacy syntax in psql in non-inline-query cases, but will
>> make psql unreservedly emit new style syntax for COPY to the backend.
>> Does that seem reasonable, or is it too much of a change for the stable
>> branch?
>>
>
> We've never promised that psql's backslash commands would work at all
> with older backends, so I think removing compatibility with pre-7.3
> backends at this point isn't a problem. OTOH, going out of your way
> to remove compatibility seems a bit pointless, so I'd vote against the
> "have_query" parts of this patch. Just change the output format.
>
>
>

The consequence will be, though, that psql will accept a syntax for
"\copy (query) ..." that the corresponding backend command would reject
were we not transforming it. That strikes me as potentially confusing.

I don't have very strong feelings either way - anybody else have an
opinion? If not, I'll go with Tom's suggestion.

cheers

andrew


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Michael Fuhr <mike(at)fuhr(dot)org>, pgsql-hackers(at)postgresql(dot)org, "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] \copy (query) delimiter syntax error
Date: 2007-02-04 22:37:49
Message-ID: 45C6603D.8090409@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
>
>> The consequence will be, though, that psql will accept a syntax for
>> "\copy (query) ..." that the corresponding backend command would reject
>> were we not transforming it. That strikes me as potentially confusing.
>>
>
> Perhaps. What about plan B: remove the legacy syntax support in \copy?
> IIRC it has not been documented since 7.2, so maybe we can finally throw
> it overboard. Thoughts?
>
>
>

I like it for 8.3 - but maybe my present patch would be better for 8.2,
as it involves less behaviour change.

cheers

andrew


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Michael Fuhr <mike(at)fuhr(dot)org>, pgsql-hackers(at)postgresql(dot)org, "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] \copy (query) delimiter syntax error
Date: 2007-02-05 14:42:52
Message-ID: 45C7426C.4080107@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Andrew Dunstan wrote:
>
>
> Tom Lane wrote:
>> Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
>>
>>> The consequence will be, though, that psql will accept a syntax for
>>> "\copy (query) ..." that the corresponding backend command would
>>> reject were we not transforming it. That strikes me as potentially
>>> confusing.
>>>
>>
>> Perhaps. What about plan B: remove the legacy syntax support in \copy?
>> IIRC it has not been documented since 7.2, so maybe we can finally throw
>> it overboard. Thoughts?
>>
>>
>>
>
> I like it for 8.3 - but maybe my present patch would be better for
> 8.2, as it involves less behaviour change.
>

While we decide this issue, which can be worked around in any case, I am
going to commit the part of the patch that nobody has objected to (and
which will fix Michael's original complaint), on HEAD and 8.2 stable, so
we can get some testing going.

cheers

andrew


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Michael Fuhr <mike(at)fuhr(dot)org>, pgsql-hackers(at)postgresql(dot)org, "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] \copy (query) delimiter syntax error
Date: 2007-02-19 23:04:43
Message-ID: 200702192304.l1JN4hL18918@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


Did we come to a conclusion on this?

---------------------------------------------------------------------------

Andrew Dunstan wrote:
> Andrew Dunstan wrote:
> >
> >
> > Tom Lane wrote:
> >> Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> >>
> >>> The consequence will be, though, that psql will accept a syntax for
> >>> "\copy (query) ..." that the corresponding backend command would
> >>> reject were we not transforming it. That strikes me as potentially
> >>> confusing.
> >>>
> >>
> >> Perhaps. What about plan B: remove the legacy syntax support in \copy?
> >> IIRC it has not been documented since 7.2, so maybe we can finally throw
> >> it overboard. Thoughts?
> >>
> >>
> >>
> >
> > I like it for 8.3 - but maybe my present patch would be better for
> > 8.2, as it involves less behaviour change.
> >
>
> While we decide this issue, which can be worked around in any case, I am
> going to commit the part of the patch that nobody has objected to (and
> which will fix Michael's original complaint), on HEAD and 8.2 stable, so
> we can get some testing going.
>
> cheers
>
> andrew
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Michael Fuhr <mike(at)fuhr(dot)org>, pgsql-hackers(at)postgresql(dot)org, "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] \copy (query) delimiter syntax error
Date: 2007-02-20 02:50:07
Message-ID: 45DA61DF.3080607@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


I think I'll go with Tom's Plan B for HEAD, but not do anything more for
8.2 than has already been done.

cheers

andrew

Bruce Momjian wrote:
> Did we come to a conclusion on this?
>
> ---------------------------------------------------------------------------
>
> Andrew Dunstan wrote:
>
>> Andrew Dunstan wrote:
>>
>>> Tom Lane wrote:
>>>
>>>> Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
>>>>
>>>>
>>>>> The consequence will be, though, that psql will accept a syntax for
>>>>> "\copy (query) ..." that the corresponding backend command would
>>>>> reject were we not transforming it. That strikes me as potentially
>>>>> confusing.
>>>>>
>>>>>
>>>> Perhaps. What about plan B: remove the legacy syntax support in \copy?
>>>> IIRC it has not been documented since 7.2, so maybe we can finally throw
>>>> it overboard. Thoughts?
>>>>
>>>>
>>>>
>>>>
>>> I like it for 8.3 - but maybe my present patch would be better for
>>> 8.2, as it involves less behaviour change.
>>>
>>>
>> While we decide this issue, which can be worked around in any case, I am
>> going to commit the part of the patch that nobody has objected to (and
>> which will fix Michael's original complaint), on HEAD and 8.2 stable, so
>> we can get some testing going.
>>
>> cheers
>>
>> andrew
>>
>> ---------------------------(end of broadcast)---------------------------
>> TIP 4: Have you searched our list archives?
>>
>> http://archives.postgresql.org
>>
>
>