1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-05 07:21:24 +03:00

Fix table_rewrite event trigger for ALTER TYPE/SET DATA TYPE CASCADE

When a composite type being used in a typed table is modified by way
of ALTER TYPE, a table rewrite occurs appearing to come from ALTER TYPE.
The existing event_trigger.c code was unable to cope with that
and raised a spurious error.  The fix is just to accept that command
tag for the event, and document this properly.

Noted while fooling with deparsing of DDL commands.  This appears to be
an oversight in commit 618c9430a.

Thanks to Mark Wong for documentation wording help.
This commit is contained in:
Alvaro Herrera
2015-02-27 18:38:33 -03:00
parent bda76c1c8c
commit 3f190f67eb
4 changed files with 27 additions and 6 deletions

View File

@ -370,6 +370,17 @@ alter table rewriteme
NOTICE: Table 'rewriteme' is being rewritten (reason = 6)
-- shouldn't trigger a table_rewrite event
alter table rewriteme alter column foo type numeric(12,4);
-- typed tables are rewritten when their type changes
create type rewritetype as (a int);
create table rewritemetoo1 of rewritetype;
create table rewritemetoo2 of rewritetype;
alter type rewritetype alter attribute a type text cascade;
NOTICE: Table 'rewritemetoo1' is being rewritten (reason = 4)
NOTICE: Table 'rewritemetoo2' is being rewritten (reason = 4)
-- but this doesn't work
create table rewritemetoo3 (a rewritetype);
alter type rewritetype alter attribute a type varchar cascade;
ERROR: cannot alter type "rewritetype" because column "rewritemetoo3.a" uses it
drop table rewriteme;
drop event trigger no_rewrite_allowed;
drop function test_evtrig_no_rewrite();

View File

@ -276,6 +276,16 @@ alter table rewriteme
-- shouldn't trigger a table_rewrite event
alter table rewriteme alter column foo type numeric(12,4);
-- typed tables are rewritten when their type changes
create type rewritetype as (a int);
create table rewritemetoo1 of rewritetype;
create table rewritemetoo2 of rewritetype;
alter type rewritetype alter attribute a type text cascade;
-- but this doesn't work
create table rewritemetoo3 (a rewritetype);
alter type rewritetype alter attribute a type varchar cascade;
drop table rewriteme;
drop event trigger no_rewrite_allowed;
drop function test_evtrig_no_rewrite();