Thread: remove psql support for ancient copy syntax

remove psql support for ancient copy syntax

From
Andrew Dunstan
Date:
The attached patch implements Tom's recent suggestion to abandon the
undocumented psql support for ancient copy syntax. If there's no
objection I will apply before long.

cheers

andrew
Index: src/bin/psql/copy.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/psql/copy.c,v
retrieving revision 1.74
diff -c -r1.74 copy.c
*** src/bin/psql/copy.c    8 Feb 2007 11:10:27 -0000    1.74
--- src/bin/psql/copy.c    15 Mar 2007 20:20:34 -0000
***************
*** 35,55 ****
   * parse_slash_copy
   * -- parses \copy command line
   *
!  * The documented preferred syntax is:
   *    \copy tablename [(columnlist)] from|to filename
   *      [ with ] [ binary ] [ oids ] [ delimiter [as] char ] [ null [as] string ]
   *
   *    \copy ( select stmt ) to filename
   *      [ with ] [ binary ] [ delimiter [as] char ] [ null [as] string ]
   *
!  * The pre-7.3 syntax was:
!  *    \copy [ binary ] tablename [(columnlist)] [with oids] from|to filename
!  *        [ [using] delimiters char ] [ with null as string ]
!  *
!  * The actual accepted syntax is a rather unholy combination of these,
!  * plus some undocumented flexibility (for instance, the clauses after
!  * WITH can appear in any order).  The accepted syntax matches what
!  * the backend grammar actually accepts (see backend/parser/gram.y).
   *
   * table name can be double-quoted and can have a schema part.
   * column names can be double-quoted.
--- 35,53 ----
   * parse_slash_copy
   * -- parses \copy command line
   *
!  * The documented syntax is:
   *    \copy tablename [(columnlist)] from|to filename
   *      [ with ] [ binary ] [ oids ] [ delimiter [as] char ] [ null [as] string ]
+  *    [ csv  [ header ] [ quote [ AS ] string ]  escape [as] string
+  *      [ force not null column [, ...] | force quote column [, ...] ] ]
   *
   *    \copy ( select stmt ) to filename
   *      [ with ] [ binary ] [ delimiter [as] char ] [ null [as] string ]
+  *    [ csv  [ header ] [ quote [ AS ] string ]  escape [as] string
+  *      [ force quote column [, ...] ] ]
   *
!  * Force quote only applies for copy to; force not null only applies for
!  * copy from.
   *
   * table name can be double-quoted and can have a schema part.
   * column names can be double-quoted.
***************
*** 216,238 ****
              goto error;
      }

-     /*
-      * Allows old COPY syntax for backward compatibility 2002-06-19
-      */
-     if (pg_strcasecmp(token, "with") == 0)
-     {
-         token = strtokx(NULL, whitespace, NULL, NULL,
-                         0, false, false, pset.encoding);
-         if (!token || pg_strcasecmp(token, "oids") != 0)
-             goto error;
-         result->oids = true;
-
-         token = strtokx(NULL, whitespace, NULL, NULL,
-                         0, false, false, pset.encoding);
-         if (!token)
-             goto error;
-     }
-
      if (pg_strcasecmp(token, "from") == 0)
          result->from = true;
      else if (pg_strcasecmp(token, "to") == 0)
--- 214,219 ----
***************
*** 267,293 ****
      token = strtokx(NULL, whitespace, NULL, NULL,
                      0, false, false, pset.encoding);

-     /*
-      * Allows old COPY syntax for backward compatibility.
-      */
-     if (token && pg_strcasecmp(token, "using") == 0)
-     {
-         token = strtokx(NULL, whitespace, NULL, NULL,
-                         0, false, false, pset.encoding);
-         if (!(token && pg_strcasecmp(token, "delimiters") == 0))
-             goto error;
-     }
-     if (token && pg_strcasecmp(token, "delimiters") == 0)
-     {
-         token = strtokx(NULL, whitespace, NULL, "'",
-                         nonstd_backslash, true, false, pset.encoding);
-         if (!token)
-             goto error;
-         result->delim = pg_strdup(token);
-         token = strtokx(NULL, whitespace, NULL, NULL,
-                         0, false, false, pset.encoding);
-     }
-
      if (token)
      {
          /*
--- 248,253 ----

Re: remove psql support for ancient copy syntax

From
Alvaro Herrera
Date:
Andrew Dunstan wrote:
>
> The attached patch implements Tom's recent suggestion to abandon the
> undocumented psql support for ancient copy syntax. If there's no
> objection I will apply before long.

Just to clarify: this means that \copy will not work when connected to
servers older than 8.0, right?



--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

Re: remove psql support for ancient copy syntax

From
Tom Lane
Date:
Alvaro Herrera <alvherre@commandprompt.com> writes:
> Andrew Dunstan wrote:
>> The attached patch implements Tom's recent suggestion to abandon the
>> undocumented psql support for ancient copy syntax. If there's no
>> objection I will apply before long.

> Just to clarify: this means that \copy will not work when connected to
> servers older than 8.0, right?

No, "ancient" means "pre-7.3".  Also it's only a problem if you try to
use one of the affected options ("with oids", "using delimiters").
Does not seem like a showstopper objection to me.  OTOH, it's also the
case that all we're saving is a couple dozen lines of code ...

            regards, tom lane