我有一个触发器功能,我只想在某些 INSERTS 实例上触发,在这种情况下,if do_backup = true
. 如果它在所有情况下都触发,我会得到一个无限循环。逻辑对我来说似乎很简单,其余的功能都有效。但是触发功能似乎没有注册我的条件并且总是运行,即使备份 = true。
CREATE OR REPLACE FUNCTION table_styles_backup() RETURNS
TRIGGER AS $table_styles_backup$
DECLARE
...
do_backup boolean;
BEGIN
SELECT backup INTO do_backup FROM table_details WHERE id=NEW.table_meta_id;
IF (do_backup = true) THEN
...
INSERT INTO table_styles_versions
(
...
)
VALUES (
...
);
END IF;
RETURN NULL;
END;
$table_styles_backup$ LANGUAGE plpgsql;
CREATE TRIGGER table_styles_backup AFTER INSERT ON table_styles
FOR EACH ROW EXECUTE PROCEDURE table_styles_backup();