Move check for binary mode and on_error option to the appropriate location.
authorFujii Masao <[email protected]>
Tue, 8 Oct 2024 09:23:43 +0000 (18:23 +0900)
committerFujii Masao <[email protected]>
Tue, 8 Oct 2024 09:23:43 +0000 (18:23 +0900)
Commit 9e2d870119 placed the check for binary mode and on_error
before default values were inserted, which was not ideal.
This commit moves the check to a more appropriate position
after default values are set.

Additionally, the comment incorrectly mentioned two checks before
inserting defaults, when there are actually three. This commit corrects
that comment.

Author: Atsushi Torikoshi
Reviewed-by: Fujii Masao
Discussion: https://postgr.es/m/8830518a-28ac-43a2-8a11-1676d9a3cdf8@oss.nttdata.com

src/backend/commands/copy.c

index befab92074e6e854d440a4de37c8998e11b1aacd..0b093dbb2a37640e739e69b376c570db68bb383e 100644 (file)
@@ -672,7 +672,7 @@ ProcessCopyOptions(ParseState *pstate,
        }
 
        /*
-        * Check for incompatible options (must do these two before inserting
+        * Check for incompatible options (must do these three before inserting
         * defaults)
         */
        if (opts_out->binary && opts_out->delim)
@@ -691,11 +691,6 @@ ProcessCopyOptions(ParseState *pstate,
                                (errcode(ERRCODE_SYNTAX_ERROR),
                                 errmsg("cannot specify %s in BINARY mode", "DEFAULT")));
 
-       if (opts_out->binary && opts_out->on_error != COPY_ON_ERROR_STOP)
-               ereport(ERROR,
-                               (errcode(ERRCODE_SYNTAX_ERROR),
-                                errmsg("only ON_ERROR STOP is allowed in BINARY mode")));
-
        /* Set defaults for omitted options */
        if (!opts_out->delim)
                opts_out->delim = opts_out->csv_mode ? "," : "\t";
@@ -900,6 +895,11 @@ ProcessCopyOptions(ParseState *pstate,
                                         errmsg("NULL specification and DEFAULT specification cannot be the same")));
        }
        /* Check on_error */
+       if (opts_out->binary && opts_out->on_error != COPY_ON_ERROR_STOP)
+               ereport(ERROR,
+                               (errcode(ERRCODE_SYNTAX_ERROR),
+                                errmsg("only ON_ERROR STOP is allowed in BINARY mode")));
+
        if (opts_out->reject_limit && !opts_out->on_error)
                ereport(ERROR,
                                (errcode(ERRCODE_INVALID_PARAMETER_VALUE),