Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit cb99679

Browse files
committed
> If it bothers you that much. I'd make a flag, cleared at the start of
> each COPY, and then where we test for CR or LF in CopyAttributeOutCSV, > if the flag is not set then set it and issue the warning. Andrew Dunstan
1 parent c1233c8 commit cb99679

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/backend/commands/copy.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.234 2004/11/06 17:46:27 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.235 2004/12/03 17:13:28 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -98,6 +98,7 @@ static bool fe_eof; /* true if detected end of copy data */
9898
static EolType eol_type; /* EOL type of input */
9999
static int client_encoding; /* remote side's character encoding */
100100
static int server_encoding; /* local encoding */
101+
static bool embedded_line_warning;
101102

102103
/* these are just for error messages, see copy_in_error_callback */
103104
static bool copy_binary; /* is it a binary copy? */
@@ -1190,6 +1191,7 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids,
11901191
attr = tupDesc->attrs;
11911192
num_phys_attrs = tupDesc->natts;
11921193
attr_count = list_length(attnumlist);
1194+
embedded_line_warning = false;
11931195

11941196
/*
11951197
* Get info about the columns we need to process.
@@ -2627,6 +2629,25 @@ CopyAttributeOutCSV(char *server_string, char *delim, char *quote,
26272629
!use_quote && (c = *test_string) != '\0';
26282630
test_string += mblen)
26292631
{
2632+
/*
2633+
* We don't know here what the surrounding line end characters
2634+
* might be. It might not even be under postgres' control. So
2635+
* we simple warn on ANY embedded line ending character.
2636+
*
2637+
* This warning will disappear when we make line parsing field-aware,
2638+
* so that we can reliably read in embedded line ending characters
2639+
* regardless of the file's line-end context.
2640+
*
2641+
*/
2642+
2643+
if (!embedded_line_warning && (c == '\n' || c == '\r') )
2644+
{
2645+
embedded_line_warning = true;
2646+
elog(WARNING,
2647+
"CSV fields with embedded linefeed or carriage return "
2648+
"characters might not be able to be reimported");
2649+
}
2650+
26302651
if (c == delimc || c == quotec || c == '\n' || c == '\r')
26312652
use_quote = true;
26322653
if (!same_encoding)

0 commit comments

Comments
 (0)