Thread: Re: [COMMITTERS] pgsql: Handle carriage returns and line feeds in

Re: [COMMITTERS] pgsql: Handle carriage returns and line feeds in

From
Andrew Dunstan
Date:

Neil Conway wrote:

> Bruce Momjian wrote:
>
>> Handle carriage returns and line feeds in COPY CSV mode.
>
>
> Would it be possible to have some regression tests for this?



will this do?

cheers

andrew

Index: src/test/regress/input/copy.source
===================================================================
RCS file: /home/cvsmirror/pgsql/src/test/regress/input/copy.source,v
retrieving revision 1.10
diff -c -r1.10 copy.source
*** src/test/regress/input/copy.source    27 Oct 2000 20:00:20 -0000    1.10
--- src/test/regress/input/copy.source    13 Mar 2005 00:30:11 -0000
***************
*** 54,56 ****
--- 54,89 ----

  COPY bt_f8_heap FROM '@abs_srcdir@/data/hash.data';

+ --- test copying in CSV mode with various styles
+ --- of embedded line ending characters
+
+ create temp table copytest (
+     style    text,
+     test     text,
+     filler    int);
+
+ insert into copytest values('DOS','abc\r\ndef',1);
+ insert into copytest values('Unix','abc\ndef',2);
+ insert into copytest values('Mac','abc\rdef',3);
+ insert into copytest values('esc\\ape','a\\r\\\r\\\n\\nb',4);
+
+ copy copytest to '@abs_builddir@/results/copytest.csv' csv;
+
+ create temp table copytest2 (like copytest);
+
+ copy copytest2 from '@abs_builddir@/results/copytest.csv' csv;
+
+ select * from copytest except select * from copytest2;
+
+ truncate copytest2;
+
+ --- same test but with an escape char different from quote char
+
+ copy copytest to '@abs_builddir@/results/copytest.csv' csv quote '\'' escape '\\';
+
+ copy copytest2 from '@abs_builddir@/results/copytest.csv' csv quote '\'' escape '\\';
+
+ select * from copytest except select * from copytest2;
+
+
+
Index: src/test/regress/output/copy.source
===================================================================
RCS file: /home/cvsmirror/pgsql/src/test/regress/output/copy.source,v
retrieving revision 1.8
diff -c -r1.8 copy.source
*** src/test/regress/output/copy.source    27 Oct 2000 20:00:22 -0000    1.8
--- src/test/regress/output/copy.source    13 Mar 2005 00:30:11 -0000
***************
*** 31,33 ****
--- 31,60 ----
  COPY bt_name_heap FROM '@abs_srcdir@/data/hash.data';
  COPY bt_txt_heap FROM '@abs_srcdir@/data/desc.data';
  COPY bt_f8_heap FROM '@abs_srcdir@/data/hash.data';
+ --- test copying in CSV mode with various styles
+ --- of embedded line ending characters
+ create temp table copytest (
+     style    text,
+     test     text,
+     filler    int);
+ insert into copytest values('DOS','abc\r\ndef',1);
+ insert into copytest values('Unix','abc\ndef',2);
+ insert into copytest values('Mac','abc\rdef',3);
+ insert into copytest values('esc\\ape','a\\r\\\r\\\n\\nb',4);
+ copy copytest to '@abs_builddir@/results/copytest.csv' csv;
+ create temp table copytest2 (like copytest);
+ copy copytest2 from '@abs_builddir@/results/copytest.csv' csv;
+ select * from copytest except select * from copytest2;
+  style | test | filler
+ -------+------+--------
+ (0 rows)
+
+ truncate copytest2;
+ --- same test but with an escape char different from quote char
+ copy copytest to '@abs_builddir@/results/copytest.csv' csv quote '\'' escape '\\';
+ copy copytest2 from '@abs_builddir@/results/copytest.csv' csv quote '\'' escape '\\';
+ select * from copytest except select * from copytest2;
+  style | test | filler
+ -------+------+--------
+ (0 rows)
+

Re: [COMMITTERS] pgsql: Handle carriage returns and line feeds in COPY

From
Bruce Momjian
Date:
Beautiful.

Your patch has been added to the PostgreSQL unapplied patches list at:

    http://momjian.postgresql.org/cgi-bin/pgpatches

It will be applied as soon as one of the PostgreSQL committers reviews
and approves it.

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


Andrew Dunstan wrote:
>
>
> Neil Conway wrote:
>
> > Bruce Momjian wrote:
> >
> >> Handle carriage returns and line feeds in COPY CSV mode.
> >
> >
> > Would it be possible to have some regression tests for this?
>
>
>
> will this do?
>
> cheers
>
> andrew
>


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

Re: [COMMITTERS] pgsql: Handle carriage returns and line feeds in COPY

From
Bruce Momjian
Date:
Patch applied.  Thanks.

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


Andrew Dunstan wrote:
>
>
> Neil Conway wrote:
>
> > Bruce Momjian wrote:
> >
> >> Handle carriage returns and line feeds in COPY CSV mode.
> >
> >
> > Would it be possible to have some regression tests for this?
>
>
>
> will this do?
>
> cheers
>
> andrew
>


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