aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2004-12-03 17:13:28 +0000
committerBruce Momjian <bruce@momjian.us>2004-12-03 17:13:28 +0000
commitcb99679aadcdff0fe5381400e1025fd59bbdf4e2 (patch)
treef5d2ee51ae0d1996e51056961f1423a146207129
parentc1233c849b69ce5c8fbdc5c54350f8944631699b (diff)
downloadpostgresql-cb99679aadcdff0fe5381400e1025fd59bbdf4e2.tar.gz
postgresql-cb99679aadcdff0fe5381400e1025fd59bbdf4e2.zip
> 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
-rw-r--r--src/backend/commands/copy.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 7ad6de5db33..dd37812ca3e 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.234 2004/11/06 17:46:27 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.235 2004/12/03 17:13:28 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -98,6 +98,7 @@ static bool fe_eof; /* true if detected end of copy data */
static EolType eol_type; /* EOL type of input */
static int client_encoding; /* remote side's character encoding */
static int server_encoding; /* local encoding */
+static bool embedded_line_warning;
/* these are just for error messages, see copy_in_error_callback */
static bool copy_binary; /* is it a binary copy? */
@@ -1190,6 +1191,7 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids,
attr = tupDesc->attrs;
num_phys_attrs = tupDesc->natts;
attr_count = list_length(attnumlist);
+ embedded_line_warning = false;
/*
* Get info about the columns we need to process.
@@ -2627,6 +2629,25 @@ CopyAttributeOutCSV(char *server_string, char *delim, char *quote,
!use_quote && (c = *test_string) != '\0';
test_string += mblen)
{
+ /*
+ * We don't know here what the surrounding line end characters
+ * might be. It might not even be under postgres' control. So
+ * we simple warn on ANY embedded line ending character.
+ *
+ * This warning will disappear when we make line parsing field-aware,
+ * so that we can reliably read in embedded line ending characters
+ * regardless of the file's line-end context.
+ *
+ */
+
+ if (!embedded_line_warning && (c == '\n' || c == '\r') )
+ {
+ embedded_line_warning = true;
+ elog(WARNING,
+ "CSV fields with embedded linefeed or carriage return "
+ "characters might not be able to be reimported");
+ }
+
if (c == delimc || c == quotec || c == '\n' || c == '\r')
use_quote = true;
if (!same_encoding)