Disallow specifying ON_ERROR option without value.
authorMasahiko Sawada <[email protected]>
Wed, 17 Apr 2024 02:31:27 +0000 (11:31 +0900)
committerMasahiko Sawada <[email protected]>
Wed, 17 Apr 2024 02:31:27 +0000 (11:31 +0900)
The ON_ERROR option of the COPY command previously allowed omitting
its value, which was inconsistent with the syntax synopsis in the
documentation and the behavior of other non-boolean COPY options.

This change enforces providing a value for the ON_ERROR option,
ensuring consistency across other non-boolean options and aligning
with the documented syntax.

Author: Atsushi Torikoshi
Reviewed-by: Masahiko Sawada
Discussion: https://postgr.es/m/a9770bf57646d90dedc3d54cf32634b2%40oss.nttdata.com

src/backend/commands/copy.c

index f75e1d700d96583bb0df5e4af1767744dfd87523..df7a4a21c9458ce29af63e58e19bd362293a56a0 100644 (file)
@@ -392,7 +392,7 @@ defGetCopyHeaderChoice(DefElem *def, bool is_from)
 static CopyOnErrorChoice
 defGetCopyOnErrorChoice(DefElem *def, ParseState *pstate, bool is_from)
 {
-   char       *sval;
+   char       *sval = defGetString(def);
 
    if (!is_from)
        ereport(ERROR,
@@ -400,16 +400,9 @@ defGetCopyOnErrorChoice(DefElem *def, ParseState *pstate, bool is_from)
                 errmsg("COPY ON_ERROR cannot be used with COPY TO"),
                 parser_errposition(pstate, def->location)));
 
-   /*
-    * If no parameter value given, assume the default value.
-    */
-   if (def->arg == NULL)
-       return COPY_ON_ERROR_STOP;
-
    /*
     * Allow "stop", or "ignore" values.
     */
-   sval = defGetString(def);
    if (pg_strcasecmp(sval, "stop") == 0)
        return COPY_ON_ERROR_STOP;
    if (pg_strcasecmp(sval, "ignore") == 0)