From 1284d2499c5d799ae80b1c82338d067d4fbfe5ab Mon Sep 17 00:00:00 2001 From: Joel Jacobson Date: Tue, 15 Oct 2024 02:34:51 +0200 Subject: [PATCH 11/16] Separate FORCE_NOT_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 90c5cb6b0f..57a1c6046a 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -877,27 +877,29 @@ ProcessCopyOptions(ParseState *pstate, "COPY FROM"))); } + /* --- FORCE_NOT_NULL option --- */ + if (opts_out->force_notnull != NIL || opts_out->force_notnull_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_NOT_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_NOT_NULL", + "COPY TO"))); + } + /* * Check for incompatible options (must do these three before inserting * defaults) */ - /* Check force_notnull */ - if (opts_out->format != COPY_FORMAT_CSV && - (opts_out->force_notnull != NIL || opts_out->force_notnull_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_NOT_NULL"))); - if ((opts_out->force_notnull != NIL || opts_out->force_notnull_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_NOT_NULL", - "COPY TO"))); - /* Check force_null */ if (opts_out->format != COPY_FORMAT_CSV && (opts_out->force_null != NIL || opts_out->force_null_all)) -- 2.45.1