我有以下觸發:觸發功能IF-ELSE的Postgres
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();
在我的if-else子句我應該檢查是否從分組表的列值number_items
不爲0。我怎麼能檢查呢?我完成的方式返回了一個錯誤。
謝謝你,它的工作吧! – dextervip 2011-12-13 20:28:04