From 942f76e595543ace5b912fd050b5961b5b3bbbf2 Mon Sep 17 00:00:00 2001 From: Joel Jacobson Date: Tue, 15 Oct 2024 02:33:35 +0200 Subject: [PATCH 10/16] Separate FORCE_QUOTE option validation into its own section. --- src/backend/commands/copy.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 025a4da15d..90c5cb6b0f 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -859,26 +859,29 @@ ProcessCopyOptions(ParseState *pstate, /* Default is no header; no action needed */ } + /* --- FORCE_QUOTE option --- */ + if (opts_out->force_quote || opts_out->force_quote_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_QUOTE"))); + + if (is_from) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + /*- 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_QUOTE", + "COPY FROM"))); + } + /* * Check for incompatible options (must do these three before inserting * defaults) */ - /* Check force_quote */ - if (opts_out->format != COPY_FORMAT_CSV && (opts_out->force_quote || - opts_out->force_quote_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_QUOTE"))); - if ((opts_out->force_quote || opts_out->force_quote_all) && is_from) - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - /*- 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_QUOTE", - "COPY FROM"))); - /* Check force_notnull */ if (opts_out->format != COPY_FORMAT_CSV && (opts_out->force_notnull != NIL || opts_out->force_notnull_all)) -- 2.45.1