如何使用3个不同表的触发器

问题描述 投票:0回答:1

亲爱的朋友StackOverFlow成员,

我有3张桌子。 bdc(bdc_id,bdc_name,bdc_gc),stt(s​​tt_id,stt_gc),bts(bts_id,bts_pmv)。

我想如果stt_gc = 'Checked'然后设置bdc_gc = 'Sent'bts_pmv = 'To do'

我使用Postgresql 11并以触发器/存储过程开始,我尝试使用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();

显然,如果我在这里,那是因为我的代码是完全错误的...我想从中学习,所以如果可能的话,解释一下我在这里做错了什么,或者我的方法是否缺乏洞察力

postgresql database-trigger
1个回答
1
投票

我认为你在update声明中寻找IFs

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;
© www.soinside.com 2019 - 2024. All rights reserved.