From 946de7ad6e092d9542394e3765f424b8d996099c Mon Sep 17 00:00:00 2001 From: Joel Jacobson Date: Tue, 15 Oct 2024 02:36:43 +0200 Subject: [PATCH 12/16] Separate FORCE_NULL option validation into its own section. --- src/backend/commands/copy.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 57a1c6046a..b5e224ee6b 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -895,27 +895,29 @@ ProcessCopyOptions(ParseState *pstate, "COPY TO"))); } + /* --- FORCE_NULL option --- */ + if (opts_out->force_null != NIL || opts_out->force_null_all) + { + if (opts_out->format != COPY_FORMAT_CSV) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + /*- translator: %s is the name of a COPY option, e.g. ON_ERROR */ + errmsg("COPY %s requires CSV mode", "FORCE_NULL"))); + + if (!is_from) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + /*- translator: first %s is the name of a COPY option, e.g. ON_ERROR, + second %s is a COPY with direction, e.g. COPY TO */ + errmsg("COPY %s cannot be used with %s", "FORCE_NULL", + "COPY TO"))); + } + /* * Check for incompatible options (must do these three before inserting * defaults) */ - /* Check force_null */ - if (opts_out->format != COPY_FORMAT_CSV && (opts_out->force_null != NIL || - opts_out->force_null_all)) - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - /*- translator: %s is the name of a COPY option, e.g. ON_ERROR */ - errmsg("COPY %s requires CSV mode", "FORCE_NULL"))); - - if ((opts_out->force_null != NIL || opts_out->force_null_all) && !is_from) - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - /*- translator: first %s is the name of a COPY option, e.g. ON_ERROR, - second %s is a COPY with direction, e.g. COPY TO */ - errmsg("COPY %s cannot be used with %s", "FORCE_NULL", - "COPY TO"))); - /* Checks specific to the CSV and TEXT formats */ if (opts_out->format == COPY_FORMAT_TEXT || opts_out->format == COPY_FORMAT_CSV) -- 2.45.1