Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier2024-10-16 23:44:50 +0000
committerMichael Paquier2024-10-16 23:44:50 +0000
commit089aac631b5ba53be0ecf8ea2e8d81388d69629c (patch)
tree72d82c83cdb28fe356793ed5ea32cceba6ea8a23 /src/backend/commands/copy.c
parent03bf0d9a4ba0fb7a908b5a79eb80e0c983b51e87 (diff)
Fix validation of COPY FORCE_NOT_NULL/FORCE_NULL for the all-column cases
This commit adds missing checks for COPY FORCE_NOT_NULL and FORCE_NULL when applied to all columns via "*". These options now correctly require CSV mode and are disallowed in COPY TO, making their behavior consistent with FORCE_QUOTE. Some regression tests are added to verify the correct behavior for the all-columns case, including FORCE_QUOTE, which was not tested. Backpatch down to 17, where support for the all-column grammar with FORCE_NOT_NULL and FORCE_NULL has been added. Author: Joel Jacobson Reviewed-by: Zhang Mingli Discussion: https://postgr.es/m/65030d1d-5f90-4fa4-92eb-f5f50389858e@app.fastmail.com Backpatch-through: 17
Diffstat (limited to 'src/backend/commands/copy.c')
-rw-r--r--src/backend/commands/copy.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 0b093dbb2a3..3485ba8663f 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -805,12 +805,14 @@ ProcessCopyOptions(ParseState *pstate,
"COPY FROM")));
/* Check force_notnull */
- if (!opts_out->csv_mode && opts_out->force_notnull != NIL)
+ if (!opts_out->csv_mode && (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 && !is_from)
+ 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,
@@ -819,13 +821,15 @@ ProcessCopyOptions(ParseState *pstate,
"COPY TO")));
/* Check force_null */
- if (!opts_out->csv_mode && opts_out->force_null != NIL)
+ if (!opts_out->csv_mode && (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 && !is_from)
+ 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,