David Fetter wrote:
> On Wed, Feb 01, 2006 at 01:16:08AM -0500, Tom Lane wrote:
> > Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > > Attached is a patch that errors for \r and \n in delimiter and
> > > null.  I kept the ERRCODE_FEATURE_NOT_SUPPORTED error code because
> > > that is what all the other error tests use in the copy code in
> > > that area.
> > 
> > I'd go with INVALID_PARAMETER_VALUE, I think.  ISTM that
> > FEATURE_NOT_SUPPORTED is appropriate for places where we might
> > someday support the case the error is rejecting.  For instance the
> > error just above your patch is for a multi-character delimiter
> > string.  That isn't completely senseless, it's just not implemented.
> > But we're not ever going to allow a delimiter setting that conflicts
> > with end-of-line, and I don't foresee allowing some other value for
> > end-of-line ;-) ... so this check isn't going to be removed someday.
> 
> I don't know why you're saying that the EOL character will never be
> changeable.  Other DBs (yes, I know that's not an argument for doing
> this, but please bear with me) let you set the "field separator" aka
> our DELIMITER and "record separator" aka our newline (or CRLF, in some
> cases. Oy!).
> 
> Anyhow, Bruce's patch still allows backslash as a delimiter, which can
> cause *all* kinds of fun if not disallowed.

OK, updated patch, which disallows backslash as a delimiter, and updated
error return code.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: src/backend/commands/copy.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/commands/copy.c,v
retrieving revision 1.257
diff -c -c -r1.257 copy.c
*** src/backend/commands/copy.c 28 Dec 2005 03:25:32 -0000      1.257
--- src/backend/commands/copy.c 1 Feb 2006 14:05:53 -0000
***************
*** 856,861 ****
--- 856,880 ----
                                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                                 errmsg("COPY delimiter must be a single 
character")));
  
+       /* Disallow end-of-line characters */
+       if (strchr(cstate->delim, '\r') != NULL ||
+           strchr(cstate->delim, '\n') != NULL)
+               ereport(ERROR,
+                               (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                                errmsg("COPY delimiter cannot be newline or 
carriage return")));
+ 
+       if (strchr(cstate->null_print, '\r') != NULL ||
+               strchr(cstate->null_print, '\n') != NULL)
+               ereport(ERROR,
+                               (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                                errmsg("COPY null cannot use newline or 
carriage return")));
+ 
+       /* Disallow backslash in non-CSV mode */
+       if (!cstate->csv_mode && strchr(cstate->delim, '\\') != NULL)
+               ereport(ERROR,
+                               (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                                errmsg("COPY delimiter cannot be backslash")));
+ 
        /* Check header */
        if (!cstate->csv_mode && cstate->header_line)
                ereport(ERROR,
---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org

Reply via email to