summaryrefslogtreecommitdiff
path: root/src/backend/commands/copy.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2017-12-08 09:18:18 -0500
committerPeter Eisentraut <peter_e@gmx.net>2017-12-08 09:18:18 -0500
commit2d2d06b7e27e3177d5bef0061801c75946871db3 (patch)
treead8f6397d6cb757ddac83cddae54faadc85377f6 /src/backend/commands/copy.c
parent0a3edbb3302173f8ac465570b6273392aa6e20b1 (diff)
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/commands/copy.c')
-rw-r--r--src/backend/commands/copy.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index bace390470f..254be28ae4f 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -23,6 +23,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"
@@ -3067,8 +3068,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 (att->attidentity)
+ {
+ NextValueExpr *nve = makeNode(NextValueExpr);
+
+ nve->seqid = getOwnedSequence(RelationGetRelid(cstate->rel),
+ attnum);
+ nve->typeId = att->atttypid;
+ defexpr = (Expr *) nve;
+ }
+ else
+ defexpr = (Expr *) build_column_default(cstate->rel, attnum);
if (defexpr != NULL)
{