From: | ProPAAS DBA <dba(at)propaas(dot)com> |
---|---|
To: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Event Trigger question |
Date: | 2017-07-14 00:32:47 |
Message-ID: | 50ad28c7-6415-9f72-d7eb-9089ece4d1d3@propaas.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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_trigger
LANGUAGE 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
From | Date | Subject | |
---|---|---|---|
Next Message | David G. Johnston | 2017-07-14 01:29:13 | Re: Event Trigger question |
Previous Message | Stephen Frost | 2017-07-13 22:56:20 | Re: LDAP authentication without OU in ldapbasedn |