Fix bug in COPY CSV mode: handle consecutive embedded newlines in COPY

input. Also add a regression test for this bug. From Andrew Dunstan.
REL8_0_STABLE
Neil Conway 21 years ago
parent 928d269abf
commit 9ac4af6847
  1. 3
      src/backend/commands/copy.c
  2. 3
      src/test/regress/expected/copy2.out
  3. 11
      src/test/regress/sql/copy2.sql

@ -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;

@ -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();

@ -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();

Loading…
Cancel
Save