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

Commitacc95f2

Browse files
committed
Add error about the use of FREEZE in COPY TO
Also clarify some other error wording.Reported-by: Kyotaro HoriguchiDiscussion:https://postgr.es/m/20220802.133046.1941977979333284049.horikyota.ntt@gmail.comBackpatch-through: master
1 parent103ed24 commitacc95f2

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

‎doc/src/sgml/ref/copy.sgml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ COPY { <replaceable class="parameter">table_name</replaceable> [ ( <replaceable
224224
open and there are no older snapshots held by this transaction. It is
225225
currently not possible to perform a <command>COPY FREEZE</command> on
226226
a partitioned table.
227+
This option is only allowed in <command>COPY FROM</command>.
227228
</para>
228229
<para>
229230
Note that all other sessions will immediately be able to see the data

‎src/backend/commands/copy.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ ProcessCopyOptions(ParseState *pstate,
671671
if (!opts_out->csv_mode&&opts_out->quote!=NULL)
672672
ereport(ERROR,
673673
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
674-
errmsg("COPYquote available only in CSV mode")));
674+
errmsg("COPYQUOTE requires CSV mode")));
675675

676676
if (opts_out->csv_mode&&strlen(opts_out->quote)!=1)
677677
ereport(ERROR,
@@ -687,7 +687,7 @@ ProcessCopyOptions(ParseState *pstate,
687687
if (!opts_out->csv_mode&&opts_out->escape!=NULL)
688688
ereport(ERROR,
689689
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
690-
errmsg("COPYescape available only in CSV mode")));
690+
errmsg("COPYESCAPE requires CSV mode")));
691691

692692
if (opts_out->csv_mode&&strlen(opts_out->escape)!=1)
693693
ereport(ERROR,
@@ -698,46 +698,52 @@ ProcessCopyOptions(ParseState *pstate,
698698
if (!opts_out->csv_mode&& (opts_out->force_quote||opts_out->force_quote_all))
699699
ereport(ERROR,
700700
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
701-
errmsg("COPYforce quote available only in CSV mode")));
701+
errmsg("COPYFORCE_QUOTE requires CSV mode")));
702702
if ((opts_out->force_quote||opts_out->force_quote_all)&&is_from)
703703
ereport(ERROR,
704704
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
705-
errmsg("COPYforce quote only available using COPYTO")));
705+
errmsg("COPYFORCE_QUOTE cannot be used with COPYFROM")));
706706

707707
/* Check force_notnull */
708708
if (!opts_out->csv_mode&&opts_out->force_notnull!=NIL)
709709
ereport(ERROR,
710710
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
711-
errmsg("COPYforce not null available only in CSV mode")));
711+
errmsg("COPYFORCE_NOT_NULL requires CSV mode")));
712712
if (opts_out->force_notnull!=NIL&& !is_from)
713713
ereport(ERROR,
714-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
715-
errmsg("COPYforce not null only available usingCOPYFROM")));
714+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
715+
errmsg("COPYFORCE_NOT_NULL cannot be used withCOPYTO")));
716716

717717
/* Check force_null */
718718
if (!opts_out->csv_mode&&opts_out->force_null!=NIL)
719719
ereport(ERROR,
720720
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
721-
errmsg("COPYforce null available only in CSV mode")));
721+
errmsg("COPYFORCE_NULL requires CSV mode")));
722722

723723
if (opts_out->force_null!=NIL&& !is_from)
724724
ereport(ERROR,
725-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
726-
errmsg("COPYforce null only available using COPYFROM")));
725+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
726+
errmsg("COPYFORCE_NULL cannot be used with COPYTO")));
727727

728728
/* Don't allow the delimiter to appear in the null string. */
729729
if (strchr(opts_out->null_print,opts_out->delim[0])!=NULL)
730730
ereport(ERROR,
731-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
732-
errmsg("COPY delimiter must not appear in the NULL specification")));
731+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
732+
errmsg("COPY delimitercharactermust not appear in the NULL specification")));
733733

734734
/* Don't allow the CSV quote char to appear in the null string. */
735735
if (opts_out->csv_mode&&
736736
strchr(opts_out->null_print,opts_out->quote[0])!=NULL)
737737
ereport(ERROR,
738-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
738+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
739739
errmsg("CSV quote character must not appear in the NULL specification")));
740740

741+
/* Check freeze */
742+
if (opts_out->freeze&& !is_from)
743+
ereport(ERROR,
744+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
745+
errmsg("COPY FREEZE cannot be used with COPY TO")));
746+
741747
if (opts_out->default_print)
742748
{
743749
if (!is_from)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,17 @@ ERROR: cannot specify DELIMITER in BINARY mode
8383
COPY x to stdin (format BINARY, null 'x');
8484
ERROR: cannot specify NULL in BINARY mode
8585
COPY x to stdin (format TEXT, force_quote(a));
86-
ERROR: COPYforce quote available only in CSV mode
86+
ERROR: COPYFORCE_QUOTE requires CSV mode
8787
COPY x from stdin (format CSV, force_quote(a));
88-
ERROR: COPYforce quote only available using COPYTO
88+
ERROR: COPYFORCE_QUOTE cannot be used with COPYFROM
8989
COPY x to stdout (format TEXT, force_not_null(a));
90-
ERROR: COPYforce not null available only in CSV mode
90+
ERROR: COPYFORCE_NOT_NULL requires CSV mode
9191
COPY x to stdin (format CSV, force_not_null(a));
92-
ERROR: COPYforce not null only available usingCOPYFROM
92+
ERROR: COPYFORCE_NOT_NULL cannot be used withCOPYTO
9393
COPY x to stdout (format TEXT, force_null(a));
94-
ERROR: COPYforce null available only in CSV mode
94+
ERROR: COPYFORCE_NULL requires CSV mode
9595
COPY x to stdin (format CSV, force_null(a));
96-
ERROR: COPYforce null only available using COPYFROM
96+
ERROR: COPYFORCE_NULL cannot be used with COPYTO
9797
-- too many columns in column list: should fail
9898
COPY x (a, b, c, d, e, d, c) from stdin;
9999
ERROR: column "d" specified more than once

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp