[ CSV [ HEADER ]
[ QUOTE [ AS ] '<replaceable class="parameter">quote</replaceable>' ]
[ ESCAPE [ AS ] '<replaceable class="parameter">escape</replaceable>' ]
- [ FORCE QUOTE <replaceable class="parameter">column</replaceable> [, ...] ]
+ [ FORCE QUOTE { <replaceable class="parameter">column</replaceable> [, ...] | * } ]
</synopsis>
</refsynopsisdiv>
<para>
In <literal>CSV</> <command>COPY TO</> mode, forces quoting to be
used for all non-<literal>NULL</> values in each specified column.
- <literal>NULL</> output is never quoted.
+ <literal>NULL</> output is never quoted. If <literal>*</> is specified,
+ non-<literal>NULL</> values for all columns of the table will be
+ quoted.
</para>
</listitem>
</varlistentry>
int num_phys_attrs;
uint64 processed;
+ /* a dummy list that represents 'all-columns' */
+ List all_columns = { T_List };
+
/* Allocate workspace and zero all fields */
cstate = (CopyStateData *) palloc0(sizeof(CopyStateData));
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("conflicting or redundant options")));
- force_quote = (List *) defel->arg;
+
+ if (IsA(defel->arg, A_Star))
+ force_quote = &all_columns;
+ else
+ force_quote = (List *) defel->arg;
}
else if (strcmp(defel->defname, "force_notnull") == 0)
{
/* Convert FORCE QUOTE name list to per-column flags, check validity */
cstate->force_quote_flags = (bool *) palloc0(num_phys_attrs * sizeof(bool));
- if (force_quote)
+ if (force_quote == &all_columns)
+ {
+ int i;
+
+ for (i = 0; i < num_phys_attrs; i++)
+ cstate->force_quote_flags[i] = true;
+ }
+ else if (force_quote)
{
List *attnums;
ListCell *cur;
{
$$ = makeDefElem("force_quote", (Node *)$3);
}
+ | FORCE QUOTE '*'
+ {
+ $$ = makeDefElem("force_quote", (Node *)makeNode(A_Star));
+ }
| FORCE NOT NULL_P columnList
{
$$ = makeDefElem("force_notnull", (Node *)$4);
"Jackson, Sam","\\h"
"It is \"perfect\"."," "
"",
+COPY y TO stdout WITH CSV FORCE QUOTE *;
+"Jackson, Sam","\h"
+"It is ""perfect""."," "
+"",
--test that we read consecutive LFs properly
CREATE TEMP TABLE testnl (a int, b text, c int);
COPY testnl FROM stdin CSV;
COPY y TO stdout WITH CSV;
COPY y TO stdout WITH CSV QUOTE '''' DELIMITER '|';
COPY y TO stdout WITH CSV FORCE QUOTE col2 ESCAPE E'\\';
+COPY y TO stdout WITH CSV FORCE QUOTE *;
--test that we read consecutive LFs properly