如何在 3 个不同的表中使用触发器
How to use trigger with 3 different tables
亲爱的 Whosebug 会员,
我有 3 张桌子。 bdc(bdc_id, bdc_name, bdc_gc), stt(stt_id, stt_gc) , bts(bts_id, bts_pmv).
我想要如果 stt_gc = 'Checked'
然后设置 bdc_gc = 'Sent'
和 bts_pmv = 'To do'
我使用 Postgresql 11 并从 triggers/stored 程序开始
我尝试检查 if
条件 stt_gc
值并根据其主键与正确的 bdc_gc
bts_pmv
匹配。
create or replace function before_stt_gc() returns trigger
language plpgsql
as
$$
begin
if new.stt_gc='Checked' then
select bdc_gc from bdc
where new.stt_id = bdc_id;
doe_gc_bts= 'Sent';
select bts_pmv from bts
where new.stt_id = bts_id;
bts_pmv = 'To do'
end if;
end;
$$;
create trigger before_stt_gc_trigger before insert or update on stt
for each row
execute procedure before_stt_gc();
很明显,如果我在这里,那是因为我的代码完全错误...
我想从中吸取教训,所以如果可能的话,请向我解释我在这里做错了什么,或者我的方法是否缺乏洞察力
我假设您正在 IF
语句中查找 update
s
if new.stt_gc='Checked' then
update bdc set bdc_gc = 'Sent'
where new.stt_id = bdc_id;
UPDATE bts SET bts_pmv = 'To do'
where new.stt_id = bts_id;
end if;
亲爱的 Whosebug 会员,
我有 3 张桌子。 bdc(bdc_id, bdc_name, bdc_gc), stt(stt_id, stt_gc) , bts(bts_id, bts_pmv).
我想要如果 stt_gc = 'Checked'
然后设置 bdc_gc = 'Sent'
和 bts_pmv = 'To do'
我使用 Postgresql 11 并从 triggers/stored 程序开始
我尝试检查 if
条件 stt_gc
值并根据其主键与正确的 bdc_gc
bts_pmv
匹配。
create or replace function before_stt_gc() returns trigger
language plpgsql
as
$$
begin
if new.stt_gc='Checked' then
select bdc_gc from bdc
where new.stt_id = bdc_id;
doe_gc_bts= 'Sent';
select bts_pmv from bts
where new.stt_id = bts_id;
bts_pmv = 'To do'
end if;
end;
$$;
create trigger before_stt_gc_trigger before insert or update on stt
for each row
execute procedure before_stt_gc();
很明显,如果我在这里,那是因为我的代码完全错误... 我想从中吸取教训,所以如果可能的话,请向我解释我在这里做错了什么,或者我的方法是否缺乏洞察力
我假设您正在 IF
语句中查找 update
s
if new.stt_gc='Checked' then
update bdc set bdc_gc = 'Sent'
where new.stt_id = bdc_id;
UPDATE bts SET bts_pmv = 'To do'
where new.stt_id = bts_id;
end if;