Commit a07e5ace authored by Tom Lane's avatar Tom Lane

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.)
parent fd9df11f
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.226 2009/07/24 19:35:44 petere Exp $ $PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.227 2009/07/25 17:04:19 tgl Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -774,7 +774,7 @@ testdb=&gt; ...@@ -774,7 +774,7 @@ testdb=&gt;
[ header ] [ header ]
[ quote [ as ] '<replaceable class="parameter">character</replaceable>' ] [ quote [ as ] '<replaceable class="parameter">character</replaceable>' ]
[ escape [ as ] '<replaceable class="parameter">character</replaceable>' ] [ escape [ as ] '<replaceable class="parameter">character</replaceable>' ]
[ force quote <replaceable class="parameter">column_list</replaceable> ] [ force quote <replaceable class="parameter">column_list</replaceable> | * ]
[ force not null <replaceable class="parameter">column_list</replaceable> ] ]</literal> [ force not null <replaceable class="parameter">column_list</replaceable> ] ]</literal>
</term> </term>
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.314 2009/07/25 13:35:32 adunstan Exp $ * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.315 2009/07/25 17:04:19 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -722,6 +722,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString) ...@@ -722,6 +722,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
List *attnamelist = stmt->attlist; List *attnamelist = stmt->attlist;
List *force_quote = NIL; List *force_quote = NIL;
List *force_notnull = NIL; List *force_notnull = NIL;
bool force_quote_all = false;
AclMode required_access = (is_from ? ACL_INSERT : ACL_SELECT); AclMode required_access = (is_from ? ACL_INSERT : ACL_SELECT);
AclMode relPerms; AclMode relPerms;
AclMode remainingPerms; AclMode remainingPerms;
...@@ -729,7 +730,6 @@ DoCopy(const CopyStmt *stmt, const char *queryString) ...@@ -729,7 +730,6 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
TupleDesc tupDesc; TupleDesc tupDesc;
int num_phys_attrs; int num_phys_attrs;
uint64 processed; uint64 processed;
bool force_quote_all = false;
/* Allocate workspace and zero all fields */ /* Allocate workspace and zero all fields */
cstate = (CopyStateData *) palloc0(sizeof(CopyStateData)); cstate = (CopyStateData *) palloc0(sizeof(CopyStateData));
...@@ -805,12 +805,11 @@ DoCopy(const CopyStmt *stmt, const char *queryString) ...@@ -805,12 +805,11 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
} }
else if (strcmp(defel->defname, "force_quote") == 0) else if (strcmp(defel->defname, "force_quote") == 0)
{ {
if (force_quote) if (force_quote || force_quote_all)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("conflicting or redundant options"))); errmsg("conflicting or redundant options")));
if (defel->arg && IsA(defel->arg, A_Star))
if (IsA(defel->arg, A_Star))
force_quote_all = true; force_quote_all = true;
else else
force_quote = (List *) defel->arg; force_quote = (List *) defel->arg;
...@@ -930,11 +929,11 @@ DoCopy(const CopyStmt *stmt, const char *queryString) ...@@ -930,11 +929,11 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
errmsg("COPY escape must be a single one-byte character"))); errmsg("COPY escape must be a single one-byte character")));
/* Check force_quote */ /* Check force_quote */
if (!cstate->csv_mode && force_quote != NIL) if (!cstate->csv_mode && (force_quote != NIL || force_quote_all))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("COPY force quote available only in CSV mode"))); errmsg("COPY force quote available only in CSV mode")));
if (force_quote != NIL && is_from) if ((force_quote != NIL || force_quote_all) && is_from)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("COPY force quote only available using COPY TO"))); errmsg("COPY force quote only available using COPY TO")));
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright (c) 2000-2009, PostgreSQL Global Development Group * Copyright (c) 2000-2009, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.80 2009/04/26 15:31:50 tgl Exp $ * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.81 2009/07/25 17:04:19 tgl Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
#include "copy.h" #include "copy.h"
...@@ -35,12 +35,12 @@ ...@@ -35,12 +35,12 @@
* \copy tablename [(columnlist)] from|to filename * \copy tablename [(columnlist)] from|to filename
* [ with ] [ binary ] [ oids ] [ delimiter [as] char ] [ null [as] string ] * [ with ] [ binary ] [ oids ] [ delimiter [as] char ] [ null [as] string ]
* [ csv [ header ] [ quote [ AS ] string ] escape [as] string * [ csv [ header ] [ quote [ AS ] string ] escape [as] string
* [ force not null column [, ...] | force quote column [, ...] ] ] * [ force not null column [, ...] | force quote column [, ...] | * ] ]
* *
* \copy ( select stmt ) to filename * \copy ( select stmt ) to filename
* [ with ] [ binary ] [ delimiter [as] char ] [ null [as] string ] * [ with ] [ binary ] [ delimiter [as] char ] [ null [as] string ]
* [ csv [ header ] [ quote [ AS ] string ] escape [as] string * [ csv [ header ] [ quote [ AS ] string ] escape [as] string
* [ force quote column [, ...] ] ] * [ force quote column [, ...] | * ] ]
* *
* Force quote only applies for copy to; force not null only applies for * Force quote only applies for copy to; force not null only applies for
* copy from. * copy from.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment