diff options
author | Peter Eisentraut | 2019-07-22 10:05:03 +0000 |
---|---|---|
committer | Peter Eisentraut | 2019-07-22 10:07:10 +0000 |
commit | 19781729f789f3c6b2540e02b96f8aa500460322 (patch) | |
tree | edff25ecb10caac6e7783cf6a04570aa9ff0d753 /src/test | |
parent | efdcca55a3df27a12efb84a18bce6ea739927b80 (diff) |
Make identity sequence management more robust
Some code could get confused when certain catalog state involving both
identity and serial sequences was present, perhaps during an attempt
to upgrade the latter to the former. Specifically, dropping the
default of a serial column maintains the ownership of the sequence by
the column, and so it would then be possible to afterwards make the
column an identity column that would now own two sequences. This
causes the code that looks up the identity sequence to error out,
making the new identity column inoperable until the ownership of the
previous sequence is released.
To fix this, make the identity sequence lookup only consider sequences
with the appropriate dependency type for an identity sequence, so it
only ever finds one (unless something else is broken). In the above
example, the old serial sequence would then be ignored. Reorganize
the various owned-sequence-lookup functions a bit to make this
clearer.
Reported-by: Laurenz Albe <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/[email protected]
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/regress/expected/identity.out | 5 | ||||
-rw-r--r-- | src/test/regress/sql/identity.sql | 8 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/test/regress/expected/identity.out b/src/test/regress/expected/identity.out index 2286519b0ca..36a239363a9 100644 --- a/src/test/regress/expected/identity.out +++ b/src/test/regress/expected/identity.out @@ -399,3 +399,8 @@ CREATE TABLE itest_child PARTITION OF itest_parent ( ) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01'); -- error ERROR: identity columns are not supported on partitions DROP TABLE itest_parent; +-- test that sequence of half-dropped serial column is properly ignored +CREATE TABLE itest14 (id serial); +ALTER TABLE itest14 ALTER id DROP DEFAULT; +ALTER TABLE itest14 ALTER id ADD GENERATED BY DEFAULT AS IDENTITY; +INSERT INTO itest14 (id) VALUES (DEFAULT); diff --git a/src/test/regress/sql/identity.sql b/src/test/regress/sql/identity.sql index 8dcfdf3dc15..4b03d24effe 100644 --- a/src/test/regress/sql/identity.sql +++ b/src/test/regress/sql/identity.sql @@ -254,3 +254,11 @@ CREATE TABLE itest_child PARTITION OF itest_parent ( f3 WITH OPTIONS GENERATED ALWAYS AS IDENTITY ) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01'); -- error DROP TABLE itest_parent; + + +-- test that sequence of half-dropped serial column is properly ignored + +CREATE TABLE itest14 (id serial); +ALTER TABLE itest14 ALTER id DROP DEFAULT; +ALTER TABLE itest14 ALTER id ADD GENERATED BY DEFAULT AS IDENTITY; +INSERT INTO itest14 (id) VALUES (DEFAULT); |