Commit 969cc16c authored by Tom Lane's avatar Tom Lane

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.
parent a0734d1e
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/copy.sgml,v 1.24 2001/09/13 15:55:24 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/copy.sgml,v 1.25 2001/12/04 21:19:57 tgl Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -227,9 +227,6 @@ ERROR: <replaceable>reason</replaceable> ...@@ -227,9 +227,6 @@ ERROR: <replaceable>reason</replaceable>
character with the keyword phrase USING DELIMITERS. Characters character with the keyword phrase USING DELIMITERS. Characters
in data fields which happen to match the delimiter character will in data fields which happen to match the delimiter character will
be backslash quoted. 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.
</para> </para>
<para> <para>
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.143 2001/12/04 19:40:16 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.144 2001/12/04 21:19:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -288,6 +288,12 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe, ...@@ -288,6 +288,12 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
if (pipe && binary) if (pipe && binary)
elog(ERROR, "COPY BINARY is not supported to stdout or from stdin"); 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. * Set up variables to avoid per-attribute overhead.
*/ */
...@@ -1009,7 +1015,7 @@ CopyReadNewline(FILE *fp, int *newline) ...@@ -1009,7 +1015,7 @@ CopyReadNewline(FILE *fp, int *newline)
* Note that the caller should not pfree the string! * Note that the caller should not pfree the string!
* *
* *isnull is set true if a null attribute, else false. * *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. * *newline remembers whether we've seen a newline ending this tuple.
* null_print says how NULL values are represented * null_print says how NULL values are represented
*/ */
...@@ -1018,6 +1024,7 @@ static char * ...@@ -1018,6 +1024,7 @@ static char *
CopyReadAttribute(FILE *fp, bool *isnull, char *delim, int *newline, char *null_print) CopyReadAttribute(FILE *fp, bool *isnull, char *delim, int *newline, char *null_print)
{ {
int c; int c;
int delimc = delim[0];
#ifdef MULTIBYTE #ifdef MULTIBYTE
int mblen; int mblen;
...@@ -1051,7 +1058,7 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim, int *newline, char *null_ ...@@ -1051,7 +1058,7 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim, int *newline, char *null_
*newline = 1; *newline = 1;
break; break;
} }
if (strchr(delim, c)) if (c == delimc)
break; break;
if (c == '\\') if (c == '\\')
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment