I have the following trigger:
CREATE OR REPLACE FUNCTION record_deleted_item() RETURNS TRIGGER AS $$
BEGIN
IF (select number_itens from grup where NEW.gruop_id = group_id) != 0 THEN
UPDATE gruop SET number_itens= (number_itens-1) WHERE gruop_id=NEW.gruop_id;
END IF;
RETURN NEW;
END; $$
LANGUAGE plpgsql;
CREATE TRIGGER deleted_item
BEFORE DELETE ON item
FOR EACH ROW EXECUTE PROCEDURE record_deleted_item();
In my if-else clause I should check if the column value number_items
from group table is not 0. How could I check it? The way I've done returns me an error.
grup
andgruop
tables or is that a typo? – mu is too short Dec 13 '11 at 20:53