mirror of
https://github.com/postgres/postgres.git
synced 2025-07-17 06:41:09 +03:00
Add a DEFAULT option to COPY FROM
This allows for a string which if an input field matches causes the column's default value to be inserted. The advantage of this is that the default can be inserted in some rows and not others, for which non-default data is available. The file_fdw extension is also modified to take allow use of this option. Israel Barth Rubio Discussion: https://postgr.es/m/CAO_rXXAcqesk6DsvioOZ5zmeEmpUN5ktZf-9=9yu+DTr0Xr8Uw@mail.gmail.com
This commit is contained in:
@ -1565,11 +1565,11 @@ BeginCopyFrom(ParseState *pstate,
|
||||
&in_func_oid, &typioparams[attnum - 1]);
|
||||
fmgr_info(in_func_oid, &in_functions[attnum - 1]);
|
||||
|
||||
/* Get default info if needed */
|
||||
if (!list_member_int(cstate->attnumlist, attnum) && !att->attgenerated)
|
||||
/* Get default info if available */
|
||||
defexprs[attnum - 1] = NULL;
|
||||
|
||||
if (!att->attgenerated)
|
||||
{
|
||||
/* attribute is NOT to be copied from input */
|
||||
/* use default value if one exists */
|
||||
Expr *defexpr = (Expr *) build_column_default(cstate->rel,
|
||||
attnum);
|
||||
|
||||
@ -1579,9 +1579,15 @@ BeginCopyFrom(ParseState *pstate,
|
||||
defexpr = expression_planner(defexpr);
|
||||
|
||||
/* Initialize executable expression in copycontext */
|
||||
defexprs[num_defaults] = ExecInitExpr(defexpr, NULL);
|
||||
defmap[num_defaults] = attnum - 1;
|
||||
num_defaults++;
|
||||
defexprs[attnum - 1] = ExecInitExpr(defexpr, NULL);
|
||||
|
||||
/* if NOT copied from input */
|
||||
/* use default value if one exists */
|
||||
if (!list_member_int(cstate->attnumlist, attnum))
|
||||
{
|
||||
defmap[num_defaults] = attnum - 1;
|
||||
num_defaults++;
|
||||
}
|
||||
|
||||
/*
|
||||
* If a default expression looks at the table being loaded,
|
||||
|
Reference in New Issue
Block a user