#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"
{
/* 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)
{
3 |
(3 rows)
+-- COPY tests
+CREATE TABLE itest9 (a int GENERATED ALWAYS AS IDENTITY, b text, c bigint);
+COPY itest9 FROM stdin;
+COPY itest9 (b, c) FROM stdin;
+SELECT * FROM itest9 ORDER BY c;
+ a | b | c
+-----+------+-----
+ 100 | foo | 200
+ 101 | bar | 201
+ 1 | foo2 | 202
+ 2 | bar2 | 203
+(4 rows)
+
-- DROP IDENTITY tests
ALTER TABLE itest4 ALTER COLUMN a DROP IDENTITY;
ALTER TABLE itest4 ALTER COLUMN a DROP IDENTITY; -- error
SELECT * FROM itest2;
+-- COPY tests
+
+CREATE TABLE itest9 (a int GENERATED ALWAYS AS IDENTITY, b text, c bigint);
+
+COPY itest9 FROM stdin;
+100 foo 200
+101 bar 201
+\.
+
+COPY itest9 (b, c) FROM stdin;
+foo2 202
+bar2 203
+\.
+
+SELECT * FROM itest9 ORDER BY c;
+
+
-- DROP IDENTITY tests
ALTER TABLE itest4 ALTER COLUMN a DROP IDENTITY;