I've got plpgsql function that does multiple inserts to multiple tables. I've also trigger that do some stuff f.g notifies some service.
The process looks like this:
- Insert into table A
- Trigger executed on table A
- Function fails on insert into table B
And then transaction is rollbacked and I've got no data in table A but trigger has executed. Furthemore there is no any DELETE on table A.
My trigger and function:
CREATE OR REPLACE FUNCTION some_function() RETURNS trigger AS
$$
BEGIN
PERFORM pg_notify('pgchannel1', row_to_json(new)::text);
RETURN NULL;
END
$$ LANGUAGE plpgsql;
CREATE TRIGGER some_trigger
AFTER INSERT
ON some_table
FOR EACH ROW
EXECUTE PROCEDURE some_function();
I would like to have this process like that:
- Insert into table A
- Insert into table B
- Trigger executed on table A / Trigger executed when function is done
How could I catch that transaction was rollbacked and not executing trigger? Is there any way to trigger function status?