summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorPeter Eisentraut2017-12-08 14:18:18 +0000
committerPeter Eisentraut2017-12-08 14:18:18 +0000
commit2d2d06b7e27e3177d5bef0061801c75946871db3 (patch)
treead8f6397d6cb757ddac83cddae54faadc85377f6 /src/test
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/test')
-rw-r--r--src/test/regress/expected/identity.out13
-rw-r--r--src/test/regress/sql/identity.sql17
2 files changed, 30 insertions, 0 deletions
diff --git a/src/test/regress/expected/identity.out b/src/test/regress/expected/identity.out
index 5fa585d6cc5..174b420a041 100644
--- a/src/test/regress/expected/identity.out
+++ b/src/test/regress/expected/identity.out
@@ -153,6 +153,19 @@ SELECT * FROM itest2;
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
diff --git a/src/test/regress/sql/identity.sql b/src/test/regress/sql/identity.sql
index e1b5a074c96..6e76dd08c86 100644
--- a/src/test/regress/sql/identity.sql
+++ b/src/test/regress/sql/identity.sql
@@ -78,6 +78,23 @@ UPDATE itest2 SET a = DEFAULT WHERE a = 2;
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;