mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-15 08:20:16 +08: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:
parent
bda76c1c8c
commit
3f190f67eb
@ -68,12 +68,11 @@
|
||||
|
||||
<para>
|
||||
The <literal>table_rewrite</> event occurs just before a table is
|
||||
rewritten by the command <literal>ALTER TABLE</literal>. While other
|
||||
rewritten by some actions of the commands <literal>ALTER TABLE</> and
|
||||
<literal>ALTER TYPE</>. While other
|
||||
control statements are available to rewrite a table,
|
||||
like <literal>CLUSTER</literal> and <literal>VACUUM</literal>,
|
||||
the <literal>table_rewrite</> event is currently only triggered by
|
||||
the <literal>ALTER TABLE</literal> command, and only when that command
|
||||
attempts to rewrite the table.
|
||||
the <literal>table_rewrite</> event is not triggered by them.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
@ -318,7 +317,7 @@
|
||||
<entry align="center"><literal>X</literal></entry>
|
||||
<entry align="center"><literal>X</literal></entry>
|
||||
<entry align="center"><literal>-</literal></entry>
|
||||
<entry align="center"><literal>-</literal></entry>
|
||||
<entry align="center"><literal>X</literal></entry>
|
||||
<entry align="center"></entry>
|
||||
</row>
|
||||
<row>
|
||||
|
@ -326,7 +326,8 @@ validate_table_rewrite_tags(const char *filtervar, List *taglist)
|
||||
static event_trigger_command_tag_check_result
|
||||
check_table_rewrite_ddl_tag(const char *tag)
|
||||
{
|
||||
if (pg_strcasecmp(tag, "ALTER TABLE") == 0)
|
||||
if (pg_strcasecmp(tag, "ALTER TABLE") == 0 ||
|
||||
pg_strcasecmp(tag, "ALTER TYPE") == 0)
|
||||
return EVENT_TRIGGER_COMMAND_TAG_OK;
|
||||
|
||||
return EVENT_TRIGGER_COMMAND_TAG_NOT_SUPPORTED;
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user