Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit089aac6

Browse files
committed
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_NULLwhen applied to all columns via "*". These options now correctlyrequire CSV mode and are disallowed in COPY TO, making their behaviorconsistent with FORCE_QUOTE.Some regression tests are added to verify the correct behavior for theall-columns case, including FORCE_QUOTE, which was not tested.Backpatch down to 17, where support for the all-column grammar withFORCE_NOT_NULL and FORCE_NULL has been added.Author: Joel JacobsonReviewed-by: Zhang MingliDiscussion:https://postgr.es/m/65030d1d-5f90-4fa4-92eb-f5f50389858e@app.fastmail.comBackpatch-through: 17
1 parent03bf0d9 commit089aac6

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

‎src/backend/commands/copy.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -805,12 +805,14 @@ ProcessCopyOptions(ParseState *pstate,
805805
"COPY FROM")));
806806

807807
/* Check force_notnull */
808-
if (!opts_out->csv_mode&&opts_out->force_notnull!=NIL)
808+
if (!opts_out->csv_mode&& (opts_out->force_notnull!=NIL||
809+
opts_out->force_notnull_all))
809810
ereport(ERROR,
810811
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
811812
/*- translator: %s is the name of a COPY option, e.g. ON_ERROR */
812813
errmsg("COPY %s requires CSV mode","FORCE_NOT_NULL")));
813-
if (opts_out->force_notnull!=NIL&& !is_from)
814+
if ((opts_out->force_notnull!=NIL||opts_out->force_notnull_all)&&
815+
!is_from)
814816
ereport(ERROR,
815817
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
816818
/*- translator: first %s is the name of a COPY option, e.g. ON_ERROR,
@@ -819,13 +821,15 @@ ProcessCopyOptions(ParseState *pstate,
819821
"COPY TO")));
820822

821823
/* Check force_null */
822-
if (!opts_out->csv_mode&&opts_out->force_null!=NIL)
824+
if (!opts_out->csv_mode&& (opts_out->force_null!=NIL||
825+
opts_out->force_null_all))
823826
ereport(ERROR,
824827
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
825828
/*- translator: %s is the name of a COPY option, e.g. ON_ERROR */
826829
errmsg("COPY %s requires CSV mode","FORCE_NULL")));
827830

828-
if (opts_out->force_null!=NIL&& !is_from)
831+
if ((opts_out->force_null!=NIL||opts_out->force_null_all)&&
832+
!is_from)
829833
ereport(ERROR,
830834
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
831835
/*- translator: first %s is the name of a COPY option, e.g. ON_ERROR,

‎src/test/regress/expected/copy2.out

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,28 @@ LINE 1: COPY x from stdin (on_error unsupported);
9898
^
9999
COPY x from stdin (format TEXT, force_quote(a));
100100
ERROR: COPY FORCE_QUOTE requires CSV mode
101+
COPY x from stdin (format TEXT, force_quote *);
102+
ERROR: COPY FORCE_QUOTE requires CSV mode
101103
COPY x from stdin (format CSV, force_quote(a));
102104
ERROR: COPY FORCE_QUOTE cannot be used with COPY FROM
105+
COPY x from stdin (format CSV, force_quote *);
106+
ERROR: COPY FORCE_QUOTE cannot be used with COPY FROM
103107
COPY x from stdin (format TEXT, force_not_null(a));
104108
ERROR: COPY FORCE_NOT_NULL requires CSV mode
109+
COPY x from stdin (format TEXT, force_not_null *);
110+
ERROR: COPY FORCE_NOT_NULL requires CSV mode
105111
COPY x to stdout (format CSV, force_not_null(a));
106112
ERROR: COPY FORCE_NOT_NULL cannot be used with COPY TO
113+
COPY x to stdout (format CSV, force_not_null *);
114+
ERROR: COPY FORCE_NOT_NULL cannot be used with COPY TO
107115
COPY x from stdin (format TEXT, force_null(a));
108116
ERROR: COPY FORCE_NULL requires CSV mode
117+
COPY x from stdin (format TEXT, force_null *);
118+
ERROR: COPY FORCE_NULL requires CSV mode
109119
COPY x to stdout (format CSV, force_null(a));
110120
ERROR: COPY FORCE_NULL cannot be used with COPY TO
121+
COPY x to stdout (format CSV, force_null *);
122+
ERROR: COPY FORCE_NULL cannot be used with COPY TO
111123
COPY x to stdout (format BINARY, on_error unsupported);
112124
ERROR: COPY ON_ERROR cannot be used with COPY TO
113125
LINE 1: COPY x to stdout (format BINARY, on_error unsupported);

‎src/test/regress/sql/copy2.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,17 @@ COPY x from stdin (format BINARY, null 'x');
7575
COPY xfrom stdin (format BINARY, on_error ignore);
7676
COPY xfrom stdin (on_error unsupported);
7777
COPY xfrom stdin (formatTEXT, force_quote(a));
78+
COPY xfrom stdin (formatTEXT, force_quote*);
7879
COPY xfrom stdin (format CSV, force_quote(a));
80+
COPY xfrom stdin (format CSV, force_quote*);
7981
COPY xfrom stdin (formatTEXT, force_not_null(a));
82+
COPY xfrom stdin (formatTEXT, force_not_null*);
8083
COPY x to stdout (format CSV, force_not_null(a));
84+
COPY x to stdout (format CSV, force_not_null*);
8185
COPY xfrom stdin (formatTEXT, force_null(a));
86+
COPY xfrom stdin (formatTEXT, force_null*);
8287
COPY x to stdout (format CSV, force_null(a));
88+
COPY x to stdout (format CSV, force_null*);
8389
COPY x to stdout (format BINARY, on_error unsupported);
8490
COPY xfrom stdin (log_verbosity unsupported);
8591
COPY xfrom stdin with (reject_limit1);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp