mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +03:00
Provide FORCE_NULL * and FORCE_NOT_NULL * options for COPY FROM
These options already exist, but you need to specify a column list for them, which can be cumbersome. We already have the possibility of all columns for FORCE QUOTE, so this is simply extending that facility to FORCE_NULL and FORCE_NOT_NULL. Author: Zhang Mingli Reviewed-By: Richard Guo, Kyatoro Horiguchi, Michael Paquier. Discussion: https://postgr.es/m/CACJufxEnVqzOFtqhexF2+AwOKFrV8zHOY3y=p+gPK6eB14pn_w@mail.gmail.com
This commit is contained in:
@ -512,9 +512,11 @@ ProcessCopyOptions(ParseState *pstate,
|
||||
}
|
||||
else if (strcmp(defel->defname, "force_not_null") == 0)
|
||||
{
|
||||
if (opts_out->force_notnull)
|
||||
if (opts_out->force_notnull || opts_out->force_notnull_all)
|
||||
errorConflictingDefElem(defel, pstate);
|
||||
if (defel->arg && IsA(defel->arg, List))
|
||||
if (defel->arg && IsA(defel->arg, A_Star))
|
||||
opts_out->force_notnull_all = true;
|
||||
else if (defel->arg && IsA(defel->arg, List))
|
||||
opts_out->force_notnull = castNode(List, defel->arg);
|
||||
else
|
||||
ereport(ERROR,
|
||||
@ -525,9 +527,11 @@ ProcessCopyOptions(ParseState *pstate,
|
||||
}
|
||||
else if (strcmp(defel->defname, "force_null") == 0)
|
||||
{
|
||||
if (opts_out->force_null)
|
||||
if (opts_out->force_null || opts_out->force_null_all)
|
||||
errorConflictingDefElem(defel, pstate);
|
||||
if (defel->arg && IsA(defel->arg, List))
|
||||
if (defel->arg && IsA(defel->arg, A_Star))
|
||||
opts_out->force_null_all = true;
|
||||
else if (defel->arg && IsA(defel->arg, List))
|
||||
opts_out->force_null = castNode(List, defel->arg);
|
||||
else
|
||||
ereport(ERROR,
|
||||
|
@ -1393,7 +1393,9 @@ BeginCopyFrom(ParseState *pstate,
|
||||
|
||||
/* Convert FORCE_NOT_NULL name list to per-column flags, check validity */
|
||||
cstate->opts.force_notnull_flags = (bool *) palloc0(num_phys_attrs * sizeof(bool));
|
||||
if (cstate->opts.force_notnull)
|
||||
if (cstate->opts.force_notnull_all)
|
||||
MemSet(cstate->opts.force_notnull_flags, true, num_phys_attrs * sizeof(bool));
|
||||
else if (cstate->opts.force_notnull)
|
||||
{
|
||||
List *attnums;
|
||||
ListCell *cur;
|
||||
@ -1416,7 +1418,9 @@ BeginCopyFrom(ParseState *pstate,
|
||||
|
||||
/* Convert FORCE_NULL name list to per-column flags, check validity */
|
||||
cstate->opts.force_null_flags = (bool *) palloc0(num_phys_attrs * sizeof(bool));
|
||||
if (cstate->opts.force_null)
|
||||
if (cstate->opts.force_null_all)
|
||||
MemSet(cstate->opts.force_null_flags, true, num_phys_attrs * sizeof(bool));
|
||||
else if (cstate->opts.force_null)
|
||||
{
|
||||
List *attnums;
|
||||
ListCell *cur;
|
||||
|
@ -582,10 +582,7 @@ BeginCopyTo(ParseState *pstate,
|
||||
cstate->opts.force_quote_flags = (bool *) palloc0(num_phys_attrs * sizeof(bool));
|
||||
if (cstate->opts.force_quote_all)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < num_phys_attrs; i++)
|
||||
cstate->opts.force_quote_flags[i] = true;
|
||||
MemSet(cstate->opts.force_quote_flags, true, num_phys_attrs * sizeof(bool));
|
||||
}
|
||||
else if (cstate->opts.force_quote)
|
||||
{
|
||||
|
Reference in New Issue
Block a user