Search Postgresql Archives

Event Trigger question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



 

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux