[GENERAL] Event Trigger question
От | ProPAAS DBA |
---|---|
Тема | [GENERAL] Event Trigger question |
Дата | |
Msg-id | 50ad28c7-6415-9f72-d7eb-9089ece4d1d3@propaas.com обсуждение исходный текст |
Ответы |
Re: [GENERAL] Event Trigger question
|
Список | pgsql-general |
Hi All;
we are creating an event trigger on ddl_command_end and I want the function to know the TABLE and COMMAND run, for example if the ddl command was an "ALTER TABLE ADD COLUMN X" then I want to pull the table and the actual alter command. We're running version 9.4 so the pg_event_trigger_ddl_commands function is not available.
I see in the 9.4 docs that the variable tg_tag is used, and I see some references to tg_event
I assume we can pass ALTER TABLE as the filter value like so:
CREATE OR REPLACE FUNCTION trap_alter_statements() RETURNS event_triggerLANGUAGE plpgsql AS $$ BEGIN RAISE EXCEPTION 'command %', tg_tag; END; $$; CREATE EVENT TRIGGER abort_ddl ON ddl_command_start WHEN TAG IN 'ALTER TABLE' EXECUTE PROCEDURE trap_alter_statements(); Questions: 1) is the above "WHEN TAG IN 'ALTER TABLE'" correct? 2) where can I find a complete list of the tg_ variables? I see this list: https://www.postgresql.org/docs/9.4/static/plpgsql-trigger.html which includes TG_NAME. OLD, NEW, etc but tg_tag and tg_event are not in the list. Are there other variables I can reference? 3) which specific variable will show me (a) the full command run and (b) the table name? Thanks in advance
В списке pgsql-general по дате отправления: