Sorry but I am new to SQL triggers and need some help.
I am after creating a trigger on UPDATE
to one of my PostgreSQL tables. The trigger calls DELETE
on a different table. My question is: Is the trigger portion of the request asynchronous or synchronous to the UPDATE
request?
For more information here are my trigger and function:
CREATE OR REPLACE FUNCTION expire_table() RETURNS trigger AS $expire_table$
BEGIN
DELETE FROM object_store WHERE p_time < NOW() - INTERVAL '6 months';
RETURN NEW;
END;
$expire_table$ LANGUAGE 'plpgsql';
CREATE TRIGGER expire_table_trigger
AFTER UPDATE ON objects
EXECUTE PROCEDURE expire_table();
My hope is that the trigger portion is asynchronous or that there is a way of making it so.
The trigger is always executed in the same transaction as the statement, so it must needs be synchronous. No way around that.
Instead of a trigger, you might consider using a queue that a worker process handles asynchronously or an architecture that uses LISTEN/NOTIFY
.
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