diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2017-12-08 09:18:18 -0500 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2017-12-08 09:39:55 -0500 |
commit | ee5b595493e1609903d55709853f5276ba85c81d (patch) | |
tree | 59dee38ffcb3eb0958cdbc66615653490e9f07df /src/backend | |
parent | a8ef4e81e6f2b7ab77aa57b986742feba57d9d86 (diff) | |
download | postgresql-ee5b595493e1609903d55709853f5276ba85c81d.tar.gz postgresql-ee5b595493e1609903d55709853f5276ba85c81d.zip |
Apply identity sequence values on COPY
A COPY into a table should apply identity sequence values just like it
does for ordinary defaults. This was previously forgotten, leading to
null values being inserted, which in turn would fail because identity
columns have not-null constraints.
Author: Michael Paquier <michael.paquier@gmail.com>
Reported-by: Steven Winfield <steven.winfield@cantabcapital.com>
Bug: #14952
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/commands/copy.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index ef301b6328a..156359476c8 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -25,6 +25,7 @@ #include "access/sysattr.h" #include "access/xact.h" #include "access/xlog.h" +#include "catalog/dependency.h" #include "catalog/pg_type.h" #include "commands/copy.h" #include "commands/defrem.h" @@ -3063,8 +3064,19 @@ BeginCopyFrom(ParseState *pstate, { /* attribute is NOT to be copied from input */ /* use default value if one exists */ - Expr *defexpr = (Expr *) build_column_default(cstate->rel, - attnum); + Expr *defexpr; + + if (attr[attnum - 1]->attidentity) + { + NextValueExpr *nve = makeNode(NextValueExpr); + + nve->seqid = getOwnedSequence(RelationGetRelid(cstate->rel), + attnum); + nve->typeId = attr[attnum - 1]->atttypid; + defexpr = (Expr *) nve; + } + else + defexpr = (Expr *) build_column_default(cstate->rel, attnum); if (defexpr != NULL) { |