I have an event trigger that executes on create, alter and drop table.
create event trigger CustomizeTable
on ddl_command_end
when tag in ( 'create table', 'alter table', 'drop table' )
execute procedure CustomizeTable();
Within the procedure I want to create a trigger on the newly created table.
create or replace function CustomizeTable() returns event_trigger as
$$
begin
EXECUTE 'create trigger DoAudit after update on XXXXXX...
end;
$$
language plpgsql;
How can I get the table name within the event trigger?
I tried using TG_TABLE_NAME as explained here but it seems that this only works on non-event-triggers.
You'll have to use the event trigger information functions described in the documentation.
For example, to get the name a newly created table, use
SELECT objid::regclass
FROM pg_event_trigger_ddl_commands();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With