I have 2 tables,
CREATE TABLE B(
offer_id serial primary key,
number_of_placement int,
constraint num_of_placement_chk check (number_of_placement >0)
);
create table a (
id serial,
offer_id int references b(offer_id),//refer to table b offer_id
status varchar(20) default 'PENDING');
and my function and trigger,
Create or replace function update_no_offer_placement_func()
returns trigger as $body$
begin
if(new.status == 'ACCEPTED') then // if the status is update with 'ACCEPTED' value
update b set number_of_placement = number_of_placement -1; //reduce the number of placement by 1
end if;
end;
$body$ language plpgsql;
CREATE TRIGGER update_no_offer_placement_trig //after update table a
AFTER update ON a
FOR EACH ROW
EXECUTE PROCEDURE update_no_offer_placement_func();
I would like to update table b's number of placement so tht it reduces its number by 1 if only the value updated in a is 'ACCEPTED'. How should i do that? I tried but its wrong.