Skip to content

Commit acc95f2

Browse files
committed
Add error about the use of FREEZE in COPY TO
Also clarify some other error wording. Reported-by: Kyotaro Horiguchi Discussion: https://postgr.es/m/20220802.133046.1941977979333284049.horikyota.ntt@gmail.com Backpatch-through: master
1 parent 103ed24 commit acc95f2

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("COPY quote available only in CSV mode")));
674+
errmsg("COPY QUOTE 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("COPY escape available only in CSV mode")));
690+
errmsg("COPY ESCAPE 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("COPY force quote available only in CSV mode")));
701+
errmsg("COPY FORCE_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("COPY force quote only available using COPY TO")));
705+
errmsg("COPY FORCE_QUOTE cannot be used with COPY FROM")));
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("COPY force not null available only in CSV mode")));
711+
errmsg("COPY FORCE_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("COPY force not null only available using COPY FROM")));
714+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
715+
errmsg("COPY FORCE_NOT_NULL cannot be used with COPY TO")));
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("COPY force null available only in CSV mode")));
721+
errmsg("COPY FORCE_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("COPY force null only available using COPY FROM")));
725+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
726+
errmsg("COPY FORCE_NULL cannot be used with COPY TO")));
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 delimiter character must 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: COPY force quote available only in CSV mode
86+
ERROR: COPY FORCE_QUOTE requires CSV mode
8787
COPY x from stdin (format CSV, force_quote(a));
88-
ERROR: COPY force quote only available using COPY TO
88+
ERROR: COPY FORCE_QUOTE cannot be used with COPY FROM
8989
COPY x to stdout (format TEXT, force_not_null(a));
90-
ERROR: COPY force not null available only in CSV mode
90+
ERROR: COPY FORCE_NOT_NULL requires CSV mode
9191
COPY x to stdin (format CSV, force_not_null(a));
92-
ERROR: COPY force not null only available using COPY FROM
92+
ERROR: COPY FORCE_NOT_NULL cannot be used with COPY TO
9393
COPY x to stdout (format TEXT, force_null(a));
94-
ERROR: COPY force null available only in CSV mode
94+
ERROR: COPY FORCE_NULL requires CSV mode
9595
COPY x to stdin (format CSV, force_null(a));
96-
ERROR: COPY force null only available using COPY FROM
96+
ERROR: COPY FORCE_NULL cannot be used with COPY TO
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy