mirror of
https://github.com/postgres/postgres.git
synced 2025-09-09 13:09:39 +03:00
Allow adding values to an enum type created in the current transaction.
Normally it is unsafe to allow ALTER TYPE ADD VALUE in a transaction block, because instances of the value could be added to indexes later in the same transaction, and then they would still be accessible even if the transaction rolls back. However, we can allow this if the enum type itself was created in the current transaction, because then any such indexes would have to go away entirely on rollback. The reason for allowing this is to support pg_upgrade's new usage of pg_restore --single-transaction: in --binary-upgrade mode, pg_dump emits enum types as a succession of ALTER TYPE ADD VALUE commands so that it can preserve the values' OIDs. The support is a bit limited, so we'll leave it undocumented. Andres Freund
This commit is contained in:
@@ -257,6 +257,33 @@ CREATE TYPE bogus AS ENUM('good', 'bad', 'ugly');
|
||||
CREATE TABLE enumtest_bogus_child(parent bogus REFERENCES enumtest_parent);
|
||||
DROP TYPE bogus;
|
||||
|
||||
--
|
||||
-- check transactional behaviour of ALTER TYPE ... ADD VALUE
|
||||
--
|
||||
CREATE TYPE bogus AS ENUM('good');
|
||||
|
||||
-- check that we can't add new values to existing enums in a transaction
|
||||
BEGIN;
|
||||
ALTER TYPE bogus ADD VALUE 'bad';
|
||||
COMMIT;
|
||||
|
||||
-- check that we recognize the case where the enum already existed but was
|
||||
-- modified in the current txn
|
||||
BEGIN;
|
||||
ALTER TYPE bogus RENAME TO bogon;
|
||||
ALTER TYPE bogon ADD VALUE 'bad';
|
||||
ROLLBACK;
|
||||
|
||||
DROP TYPE bogus;
|
||||
|
||||
-- check that we *can* add new values to existing enums in a transaction,
|
||||
-- if the type is new as well
|
||||
BEGIN;
|
||||
CREATE TYPE bogus AS ENUM();
|
||||
ALTER TYPE bogus ADD VALUE 'good';
|
||||
ALTER TYPE bogus ADD VALUE 'ugly';
|
||||
ROLLBACK;
|
||||
|
||||
--
|
||||
-- Cleanup
|
||||
--
|
||||
|
Reference in New Issue
Block a user