From: Tom Lane Date: Sat, 25 Jul 2009 17:04:19 +0000 (+0000) Subject: Code review for FORCE QUOTE * patch: fix error checking to consider FORCE X-Git-Url: http://waps.l3s.uni-hannover.de/gitweb/?a=commitdiff_plain;h=9ccb3ea86d5adbf5c315e98a449a0aeb11716c02;p=users%2Fsimon%2Fpostgres.git 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.) --- diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index 56f61349a8..b86c2d0895 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -774,7 +774,7 @@ testdb=> [ header ] [ quote [ as ] 'character' ] [ escape [ as ] 'character' ] - [ force quote column_list ] + [ force quote column_list | * ] [ force not null column_list ] ] diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index f74eb35937..41578b74b8 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -722,6 +722,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString) List *attnamelist = stmt->attlist; List *force_quote = NIL; List *force_notnull = NIL; + bool force_quote_all = false; AclMode required_access = (is_from ? ACL_INSERT : ACL_SELECT); AclMode relPerms; AclMode remainingPerms; @@ -729,8 +730,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString) TupleDesc tupDesc; int num_phys_attrs; uint64 processed; - bool force_quote_all = false; - + /* Allocate workspace and zero all fields */ cstate = (CopyStateData *) palloc0(sizeof(CopyStateData)); @@ -805,12 +805,11 @@ DoCopy(const CopyStmt *stmt, const char *queryString) } else if (strcmp(defel->defname, "force_quote") == 0) { - if (force_quote) + if (force_quote || force_quote_all) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("conflicting or redundant options"))); - - if (IsA(defel->arg, A_Star)) + if (defel->arg && IsA(defel->arg, A_Star)) force_quote_all = true; else force_quote = (List *) defel->arg; @@ -930,11 +929,11 @@ DoCopy(const CopyStmt *stmt, const char *queryString) errmsg("COPY escape must be a single one-byte character"))); /* Check force_quote */ - if (!cstate->csv_mode && force_quote != NIL) + if (!cstate->csv_mode && (force_quote != NIL || force_quote_all)) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), 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, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("COPY force quote only available using COPY TO"))); diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c index 5b9c6059d9..2c88520b87 100644 --- a/src/bin/psql/copy.c +++ b/src/bin/psql/copy.c @@ -35,12 +35,12 @@ * \copy tablename [(columnlist)] from|to filename * [ with ] [ binary ] [ oids ] [ delimiter [as] char ] [ null [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 * [ with ] [ binary ] [ delimiter [as] char ] [ null [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 * copy from.