我正在尝试编写插入
时执行的触发器create table audy(id int,stat varchar(10),psq)
insert into audy(1,ps,2014-01-01,2014-01-02)
insert into audy(2,ss,2014-02-05,2014-02-06)
--trigger
create trigger audytrigg After insert on aud
for each row execute ProLayer()
--stored proc
CREATE OR REPLACE FUNCTION ProLayer()
RETURNS trigger AS $Agg_Layer$
BEGIN
if New.id=1 then
insert into agg(id,sales,qty)
select id,sum(sales),sales(qty) from perf a inner join audy b on a.id=b.id
where a.id between b.start and b.end
end
现在如果作业成功,那么我必须插入Aud(stat,psq)值(现在是'su'),如果失败则回滚。
我怎样才能在postgres中做到这一点?