how can I update the event trigger? - postgresql

I create event trigger:
CREATE EVENT TRIGGER tr_event_begin ON ddl_command_start EXECUTE PROCEDURE event_trigger_begin();
later I need to change the event or procedure. Now, I have to do so:
DROP EVENT TRIGGER tr_event_begin;
CREATE EVENT TRIGGER tr_event_begin ON ddl_command_end EXECUTE PROCEDURE myProc();
how to do it differently? Without removing the trigger, update it... sql only.

I think your proposal is the most elegant way to do it.
https://www.postgresql.org/docs/current/static/sql-altereventtrigger.html

Related

Enabling and Disabling a trigger in a Postgres function

I have a trigger on a table and I want to catch the messages that are introduced between an interval. I had created a function who recive an integer() as a parameter.
The pseudocode is something like this:
alter table <table_name> enable trigger <trigger_name>;
PERFORM pg_sleep(<nrofseconds>);
alter table <table_name> disable trigger <trigger_name>;
The problem is that, a Postgres function works as a single transaction and the trigger is enabled, then disabled at the end of execution, when commit is called so it does not track anything.
How can I solve this problem?

execute a trigger when I create a table

I would like to know if a trigger on a system table of PostgreSQL can be executed when I create a table
I need to add 2 functions on each table of my database and I would like to do it dynamically
Thanks
This can be done with an event trigger:
CREATE OR REPLACE FUNCTION on_create_table_func()
RETURNS event_trigger AS $$
BEGIN
-- your code here
END
$$
LANGUAGE plpgsql;
CREATE EVENT TRIGGER
on_create_table ON ddl_command_end
WHEN TAG IN ('CREATE TABLE')
EXECUTE PROCEDURE on_create_table_func();
Note that there is no way to directly execute any query on the newly created table, or even get its name.
I don't know what you mean by "add 2 functions on each table" since functions don't belong to a specific table, but if you need to perform an operation specific for the new tables, this might not be for you.
I know it's an old question but now it has been implemented in version 9.3, or at least partially
http://www.postgresql.org/docs/9.3/static/event-trigger-definition.html
You're looking for "DDL Triggers". They're not implemented in PostgreSQL. Neither you can add triggers to system tables. Look at this forum entry:
Adding ddl audit trigger

Multiple triggers on the same event

I would like to ask you which are the RDBMS's which support multiple triggers for the same event. For instance I have a table called MyTable and I would like to create trigger1 and trigger2 which should run before insert into the given table. Is there an RDBMS which supports this?
Why do you need two triggers on the same "before insert" event? Can't you combine the trigger code into one?

the questions about quartz.net ' trigger

i know ,in quartz.net ,change a old trigger like below,
scheduler.RescheduleJob(oldname,oldgroup,newtrigger);
it need have not the same name with old trigger name,
but i need to change trigger with the same trigger name,is there anyway to solve?
You can also delete the trigger using scheduler.UnscheduleJob(triggerName, groupName)and then schedule the job again.

Learning about DB2 triggers

Hi I am trying to figure out the syntax for triggers. I have two tables one called tagged_in and the other notification. So I want to make a trigger where when an insert is called in tagged_in I want to insert a tuple in notification.
The manuals are available at the DB2 InfoCenter. Did you read the CREATE TRIGGER statement information yet? If not, why not? If so, what did you try, and what error did you get?
Something like this
CREATE TRIGGER TEST_TRIGGER
AFTER INSERT ON TAGGED_IN
REFERENCING NEW AS NEW_TAG
FOR EACH ROW
BEGIN ATOMIC
INSERT INTO NOTIFICATION
VALUES (NEW_TAG.FIELD1,NEW_TAG.FIELD2);
END