From 9ac4af684737f9c20ba60eda67ac41c41d41ea3e Mon Sep 17 00:00:00 2001 From: Neil Conway Date: Fri, 13 May 2005 06:35:25 +0000 Subject: [PATCH] Fix bug in COPY CSV mode: handle consecutive embedded newlines in COPY input. Also add a regression test for this bug. From Andrew Dunstan. --- src/backend/commands/copy.c | 3 ++- src/test/regress/expected/copy2.out | 3 +++ src/test/regress/sql/copy2.sql | 11 +++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 9f99bdd9e48..79ffac04df0 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -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; diff --git a/src/test/regress/expected/copy2.out b/src/test/regress/expected/copy2.out index 6a4769adac1..40dd7f24af2 100644 --- a/src/test/regress/expected/copy2.out +++ b/src/test/regress/expected/copy2.out @@ -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(); diff --git a/src/test/regress/sql/copy2.sql b/src/test/regress/sql/copy2.sql index 78bbf4182e5..eb1a69c0955 100644 --- a/src/test/regress/sql/copy2.sql +++ b/src/test/regress/sql/copy2.sql @@ -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(); -- 2.39.5