Skip to content

Commit a07e5ac

Browse files
committed
Code review for FORCE QUOTE * patch: fix error checking to consider FORCE
QUOTE * as a variety of FORCE QUOTE, and update psql documentation to include the option. (The actual psql code doesn't seem to need any changes.)
1 parent fd9df11 commit a07e5ac

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

doc/src/sgml/ref/psql-ref.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.226 2009/07/24 19:35:44 petere Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.227 2009/07/25 17:04:19 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -774,7 +774,7 @@ testdb=&gt;
774774
[ header ]
775775
[ quote [ as ] '<replaceable class="parameter">character</replaceable>' ]
776776
[ escape [ as ] '<replaceable class="parameter">character</replaceable>' ]
777-
[ force quote <replaceable class="parameter">column_list</replaceable> ]
777+
[ force quote <replaceable class="parameter">column_list</replaceable> | * ]
778778
[ force not null <replaceable class="parameter">column_list</replaceable> ] ]</literal>
779779
</term>
780780

src/backend/commands/copy.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.314 2009/07/25 13:35:32 adunstan Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.315 2009/07/25 17:04:19 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -722,15 +722,15 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
722722
List *attnamelist = stmt->attlist;
723723
List *force_quote = NIL;
724724
List *force_notnull = NIL;
725+
bool force_quote_all = false;
725726
AclMode required_access = (is_from ? ACL_INSERT : ACL_SELECT);
726727
AclMode relPerms;
727728
AclMode remainingPerms;
728729
ListCell *option;
729730
TupleDesc tupDesc;
730731
int num_phys_attrs;
731732
uint64 processed;
732-
bool force_quote_all = false;
733-
733+
734734
/* Allocate workspace and zero all fields */
735735
cstate = (CopyStateData *) palloc0(sizeof(CopyStateData));
736736

@@ -805,12 +805,11 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
805805
}
806806
else if (strcmp(defel->defname, "force_quote") == 0)
807807
{
808-
if (force_quote)
808+
if (force_quote || force_quote_all)
809809
ereport(ERROR,
810810
(errcode(ERRCODE_SYNTAX_ERROR),
811811
errmsg("conflicting or redundant options")));
812-
813-
if (IsA(defel->arg, A_Star))
812+
if (defel->arg && IsA(defel->arg, A_Star))
814813
force_quote_all = true;
815814
else
816815
force_quote = (List *) defel->arg;
@@ -930,11 +929,11 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
930929
errmsg("COPY escape must be a single one-byte character")));
931930

932931
/* Check force_quote */
933-
if (!cstate->csv_mode && force_quote != NIL)
932+
if (!cstate->csv_mode && (force_quote != NIL || force_quote_all))
934933
ereport(ERROR,
935934
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
936935
errmsg("COPY force quote available only in CSV mode")));
937-
if (force_quote != NIL && is_from)
936+
if ((force_quote != NIL || force_quote_all) && is_from)
938937
ereport(ERROR,
939938
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
940939
errmsg("COPY force quote only available using COPY TO")));

src/bin/psql/copy.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.80 2009/04/26 15:31:50 tgl Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.81 2009/07/25 17:04:19 tgl Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "copy.h"
@@ -35,12 +35,12 @@
3535
* \copy tablename [(columnlist)] from|to filename
3636
* [ with ] [ binary ] [ oids ] [ delimiter [as] char ] [ null [as] string ]
3737
* [ csv [ header ] [ quote [ AS ] string ] escape [as] string
38-
* [ force not null column [, ...] | force quote column [, ...] ] ]
38+
* [ force not null column [, ...] | force quote column [, ...] | * ] ]
3939
*
4040
* \copy ( select stmt ) to filename
4141
* [ with ] [ binary ] [ delimiter [as] char ] [ null [as] string ]
4242
* [ csv [ header ] [ quote [ AS ] string ] escape [as] string
43-
* [ force quote column [, ...] ] ]
43+
* [ force quote column [, ...] | * ] ]
4444
*
4545
* Force quote only applies for copy to; force not null only applies for
4646
* copy from.

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