can you do rollback in a trigger function?

From: Quang Thoi <Quang_Thoi(at)symantec(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: can you do rollback in a trigger function?
Date: 2013-10-15 18:38:35
Message-ID: 571602E8CBF2CE4B8D025AD126A299632B70A422FB@TUS1XCHEVSPIN32.SYMC.SYMANTEC.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I want to roll back deletion if there is a reference (FK) in another table.
Can I explicitly call a rollback inside a function?

CREATE OR REPLACE FUNCTION pre_del_prod_proc()
returns trigger as $$
begin
if exists (select 1 from host_config where config_id = OLD.id) then
rollback;
end if;
end;
$$ language plpqsql;

CREATE TRIGGER pre_del_prod_proc
before delete on prod_config
for each row execute procedure pre_del_prod_proc();

Thanks,
Quang.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Vick Khera 2013-10-15 19:00:10 Re: can you do rollback in a trigger function?
Previous Message David Johnston 2013-10-15 17:25:22 Re: Fwd: String reverse funtion?