From d2d51183419b05b4ec774057c0e717fd69819f83 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 4 Dec 2001 21:19:57 +0000 Subject: [PATCH] Enforce restriction that COPY DELIMITERS string must be exactly one character; replace strchr() search with simple comparison to speed up COPY IN. Per discussion in pghackers. --- doc/src/sgml/ref/copy.sgml | 3 --- src/backend/commands/copy.c | 11 +++++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/doc/src/sgml/ref/copy.sgml b/doc/src/sgml/ref/copy.sgml index 12f683e348..09f1ac19e9 100644 --- a/doc/src/sgml/ref/copy.sgml +++ b/doc/src/sgml/ref/copy.sgml @@ -227,9 +227,6 @@ ERROR: reason character with the keyword phrase USING DELIMITERS. Characters in data fields which happen to match the delimiter character will be backslash quoted. - Note that the delimiter is always a single character. - If multiple characters are specified in the delimiter string, - only the first character is used. diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index c8f3092482..f1273dbe13 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -288,6 +288,12 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe, if (pipe && binary) elog(ERROR, "COPY BINARY is not supported to stdout or from stdin"); + /* + * Presently, only single-character delimiter strings are supported. + */ + if (strlen(delim) != 1) + elog(ERROR, "COPY delimiter must be a single character"); + /* * Set up variables to avoid per-attribute overhead. */ @@ -1009,7 +1015,7 @@ CopyReadNewline(FILE *fp, int *newline) * Note that the caller should not pfree the string! * * *isnull is set true if a null attribute, else false. - * delim is the string of acceptable delimiter characters(s). + * delim is the column delimiter string (currently always 1 character). * *newline remembers whether we've seen a newline ending this tuple. * null_print says how NULL values are represented */ @@ -1018,6 +1024,7 @@ static char * CopyReadAttribute(FILE *fp, bool *isnull, char *delim, int *newline, char *null_print) { int c; + int delimc = delim[0]; #ifdef MULTIBYTE int mblen; @@ -1051,7 +1058,7 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim, int *newline, char *null_ *newline = 1; break; } - if (strchr(delim, c)) + if (c == delimc) break; if (c == '\\') { -- 2.39.5