]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix bug in COPY CSV mode: handle consecutive embedded newlines in COPY
authorNeil Conway <neilc@samurai.com>
Fri, 13 May 2005 06:35:25 +0000 (06:35 +0000)
committerNeil Conway <neilc@samurai.com>
Fri, 13 May 2005 06:35:25 +0000 (06:35 +0000)
input. Also add a regression test for this bug. From Andrew Dunstan.

src/backend/commands/copy.c
src/test/regress/expected/copy2.out
src/test/regress/sql/copy2.sql

index 9f99bdd9e482868a29f5d92a572b8c40990689e4..79ffac04df020a40725526442e296151c6b2a71e 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.236 2004/12/31 21:59:41 pgsql Exp $
+ *       $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.236.4.1 2005/05/13 06:35:25 neilc Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -2395,6 +2395,7 @@ CopyReadAttributeCSV(const char *delim, const char *null_print, char *quote,
                        if (done && line_buf.len == 0)
                                break;
                        start_cursor = line_buf.cursor;
+                       continue;
                }
 
                end_cursor = line_buf.cursor;
index 6a4769adac11f9425cad21f80672d512e5d8e9e0..40dd7f24af20b26db01e9e2a3f06d02f35a0a747 100644 (file)
@@ -191,6 +191,9 @@ COPY y TO stdout WITH CSV FORCE QUOTE col2 ESCAPE '\\';
 "Jackson, Sam","\\h"
 "It is \"perfect\"."," "
 "",
+--test that we read consecutive LFs properly
+CREATE TEMP TABLE testnl (a int, b text, c int);
+COPY testnl FROM stdin CSV;
 DROP TABLE x, y;
 DROP FUNCTION fn_x_before();
 DROP FUNCTION fn_x_after();
index 78bbf4182e597f6234d2ba5ae0ae0004dcf216b3..eb1a69c095555b06ce9af2a990c353cdbe1ba153 100644 (file)
@@ -129,6 +129,17 @@ COPY y TO stdout WITH CSV;
 COPY y TO stdout WITH CSV QUOTE '''' DELIMITER '|';
 COPY y TO stdout WITH CSV FORCE QUOTE col2 ESCAPE '\\';
 
+--test that we read consecutive LFs properly
+
+CREATE TEMP TABLE testnl (a int, b text, c int);
+
+COPY testnl FROM stdin CSV;
+1,"a field with two LFs
+
+inside",2
+\.
+
+
 DROP TABLE x, y;
 DROP FUNCTION fn_x_before();
 DROP FUNCTION fn_x_after();