Re: COPY CSV header line feature

Lists: pgsql-patches
From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: COPY CSV header line feature
Date: 2005-03-13 23:32:20
Message-ID: 4234CD84.6010004@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-patches


The attached patch implements the previously discussed header line
feature for CSV mode COPY. It is triggered by the keyword HEADER (blame
Bruce - he chose it ;-) ).

On input this feature causes the first line to be ignored; on output it
generates a line of column names. This will make playing with
spreadsheets potentially a lot nicer.

Docs and regression tests will be forthcoming.

cheers

andrew

Attachment Content-Type Size
csv-header.patch text/x-patch 9.6 KB

From: Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: COPY CSV header line feature
Date: 2005-03-16 00:21:02
Message-ID: 20050316002102.GE17051@dcc.uchile.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-patches

On Sun, Mar 13, 2005 at 06:32:20PM -0500, Andrew Dunstan wrote:

> The attached patch implements the previously discussed header line
> feature for CSV mode COPY. It is triggered by the keyword HEADER (blame
> Bruce - he chose it ;-) ).

I think you should add the new reserved keyword to the
unreserved_keywords list or some other.

--
Alvaro Herrera (<alvherre[(at)]dcc(dot)uchile(dot)cl>)
"No hay hombre que no aspire a la plenitud, es decir,
la suma de experiencias de que un hombre es capaz"


From: "Andrew Dunstan" <andrew(at)dunslane(dot)net>
To: <alvherre(at)dcc(dot)uchile(dot)cl>
Cc: <pgsql-patches(at)postgresql(dot)org>
Subject: Re: COPY CSV header line feature
Date: 2005-03-16 02:55:36
Message-ID: 1214.24.211.165.134.1110941736.squirrel@www.dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-patches

Alvaro Herrera said:
> On Sun, Mar 13, 2005 at 06:32:20PM -0500, Andrew Dunstan wrote:
>
>> The attached patch implements the previously discussed header line
>> feature for CSV mode COPY. It is triggered by the keyword HEADER
>> (blame Bruce - he chose it ;-) ).
>
> I think you should add the new reserved keyword to the
> unreserved_keywords list or some other.
>

Please be more specific. I'll be happy to add in anything I've missed.

cheers

andrew


From: Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: COPY CSV header line feature
Date: 2005-03-16 03:13:16
Message-ID: 20050316031316.GA25421@dcc.uchile.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-patches

On Tue, Mar 15, 2005 at 08:55:36PM -0600, Andrew Dunstan wrote:
> Alvaro Herrera said:
> > On Sun, Mar 13, 2005 at 06:32:20PM -0500, Andrew Dunstan wrote:
> >
> >> The attached patch implements the previously discussed header line
> >> feature for CSV mode COPY. It is triggered by the keyword HEADER
> >> (blame Bruce - he chose it ;-) ).
> >
> > I think you should add the new reserved keyword to the
> > unreserved_keywords list or some other.
>
> Please be more specific. I'll be happy to add in anything I've missed.

The Postgres grammar classifies keywords in one of several lists, in
order to make them available as names to users (column names, function
names, etc). So each time you create a new keyword and add it to the
keywords.c list, you have to add it to one of the lists on gram.y too.
See gram.y line 7669 ff.

I'd add a comment on this on gram.y:

Index: gram.y
===================================================================
RCS file: /home/alvherre/cvs/pgsql/src/backend/parser/gram.y,v
retrieving revision 2.484
diff -c -w -b -B -c -r2.484 gram.y
*** gram.y 14 Mar 2005 00:19:36 -0000 2.484
--- gram.y 16 Mar 2005 03:12:48 -0000
***************
*** 327,333 ****
/*
* If you make any token changes, update the keyword table in
* parser/keywords.c and add new keywords to the appropriate one of
! * the reserved-or-not-so-reserved keyword lists, below.
*/

/* ordinary key words in alphabetical order */
--- 327,334 ----
/*
* If you make any token changes, update the keyword table in
* parser/keywords.c and add new keywords to the appropriate one of
! * the reserved-or-not-so-reserved keyword lists, below; search this
! * file for "Name classification hierarchy."
*/

/* ordinary key words in alphabetical order */

--
Alvaro Herrera (<alvherre[(at)]dcc(dot)uchile(dot)cl>)
Tulio: oh, para qué servirá este boton, Juan Carlos?
Policarpo: No, aléjense, no toquen la consola!
Juan Carlos: Lo apretaré una y otra vez.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: COPY CSV header line feature
Date: 2005-03-16 05:22:54
Message-ID: 2545.1110950574@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-patches

Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl> writes:
> I think you should add the new reserved keyword to the
> unreserved_keywords list or some other.

*Every* keyword needs to be in one of those lists. I'd like to have
some sort of automatic enforcement of this, because forgetting to
add a new keyword to the right list is an everyday error.

I've been thinking that it would be good if the table in keywords.c
included an indication of the reservation category of each keyword.
So one possible approach is to do that and then somehow check that
the gram.y grammar agrees --- or even better, mechanically generate
the keyword category productions in gram.y from the keywords.c data.
Not sure just how to do that though.

Any ideas?

regards, tom lane


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: COPY CSV header line feature
Date: 2005-03-16 12:44:41
Message-ID: 42382A39.1090706@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-patches


ammended patch attached. sorry for the oversight. I agree with Tom's
remark - it's far too easy to miss this.

cheers

andrew

Alvaro Herrera wrote:

>On Tue, Mar 15, 2005 at 08:55:36PM -0600, Andrew Dunstan wrote:
>
>
>>Alvaro Herrera said:
>>
>>
>>>On Sun, Mar 13, 2005 at 06:32:20PM -0500, Andrew Dunstan wrote:
>>>
>>>
>>>
>>>>The attached patch implements the previously discussed header line
>>>>feature for CSV mode COPY. It is triggered by the keyword HEADER
>>>>(blame Bruce - he chose it ;-) ).
>>>>
>>>>
>>>I think you should add the new reserved keyword to the
>>>unreserved_keywords list or some other.
>>>
>>>
>>Please be more specific. I'll be happy to add in anything I've missed.
>>
>>
>
>The Postgres grammar classifies keywords in one of several lists, in
>order to make them available as names to users (column names, function
>names, etc). So each time you create a new keyword and add it to the
>keywords.c list, you have to add it to one of the lists on gram.y too.
>See gram.y line 7669 ff.
>
>I'd add a comment on this on gram.y:
>
>Index: gram.y
>===================================================================
>RCS file: /home/alvherre/cvs/pgsql/src/backend/parser/gram.y,v
>retrieving revision 2.484
>diff -c -w -b -B -c -r2.484 gram.y
>*** gram.y 14 Mar 2005 00:19:36 -0000 2.484
>--- gram.y 16 Mar 2005 03:12:48 -0000
>***************
>*** 327,333 ****
> /*
> * If you make any token changes, update the keyword table in
> * parser/keywords.c and add new keywords to the appropriate one of
>! * the reserved-or-not-so-reserved keyword lists, below.
> */
>
> /* ordinary key words in alphabetical order */
>--- 327,334 ----
> /*
> * If you make any token changes, update the keyword table in
> * parser/keywords.c and add new keywords to the appropriate one of
>! * the reserved-or-not-so-reserved keyword lists, below; search this
>! * file for "Name classification hierarchy."
> */
>
> /* ordinary key words in alphabetical order */
>
>
>

Attachment Content-Type Size
csv-header2.patch text/x-patch 9.7 KB

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>, pgsql-patches(at)postgresql(dot)org
Subject: Re: COPY CSV header line feature
Date: 2005-05-06 03:43:00
Message-ID: 200505060343.j463h0w07376@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-patches


Here is an updated version of this patch, with documentation changes.

I have already updated the gram.y comment you suggested.

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

Andrew Dunstan wrote:
>
> ammended patch attached. sorry for the oversight. I agree with Tom's
> remark - it's far too easy to miss this.
>
> cheers
>
> andrew
>
> Alvaro Herrera wrote:
>
> >On Tue, Mar 15, 2005 at 08:55:36PM -0600, Andrew Dunstan wrote:
> >
> >
> >>Alvaro Herrera said:
> >>
> >>
> >>>On Sun, Mar 13, 2005 at 06:32:20PM -0500, Andrew Dunstan wrote:
> >>>
> >>>
> >>>
> >>>>The attached patch implements the previously discussed header line
> >>>>feature for CSV mode COPY. It is triggered by the keyword HEADER
> >>>>(blame Bruce - he chose it ;-) ).
> >>>>
> >>>>
> >>>I think you should add the new reserved keyword to the
> >>>unreserved_keywords list or some other.
> >>>
> >>>
> >>Please be more specific. I'll be happy to add in anything I've missed.
> >>
> >>
> >
> >The Postgres grammar classifies keywords in one of several lists, in
> >order to make them available as names to users (column names, function
> >names, etc). So each time you create a new keyword and add it to the
> >keywords.c list, you have to add it to one of the lists on gram.y too.
> >See gram.y line 7669 ff.
> >
> >I'd add a comment on this on gram.y:
> >
> >Index: gram.y
> >===================================================================
> >RCS file: /home/alvherre/cvs/pgsql/src/backend/parser/gram.y,v
> >retrieving revision 2.484
> >diff -c -w -b -B -c -r2.484 gram.y
> >*** gram.y 14 Mar 2005 00:19:36 -0000 2.484
> >--- gram.y 16 Mar 2005 03:12:48 -0000
> >***************
> >*** 327,333 ****
> > /*
> > * If you make any token changes, update the keyword table in
> > * parser/keywords.c and add new keywords to the appropriate one of
> >! * the reserved-or-not-so-reserved keyword lists, below.
> > */
> >
> > /* ordinary key words in alphabetical order */
> >--- 327,334 ----
> > /*
> > * If you make any token changes, update the keyword table in
> > * parser/keywords.c and add new keywords to the appropriate one of
> >! * the reserved-or-not-so-reserved keyword lists, below; search this
> >! * file for "Name classification hierarchy."
> > */
> >
> > /* ordinary key words in alphabetical order */
> >
> >
> >

>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

Attachment Content-Type Size
unknown_filename text/plain 14.1 KB