请帮我纠正sql语句:
CREATE TRIGGER transaction_insert
AFTER INSERT ON transaction
FOR EACH ROW
WHEN (NEW.tr_type = 55)
EXECUTE PROCEDURE pg_notify('check_close', to_char(NEW.n_transaction, 999999));
我需要在添加tr_type=55
的行时收到通知。
tr_type
是int
。 n_transaction是int
。
Postgresql 8.3.4
请帮忙!
答案 0 :(得分:2)
尝试以下方法:
CREATE TRIGGER transaction_insert
AFTER INSERT ON transaction
FOR EACH ROW EXECUTE PROCEDURE transaction_insert_check_close();
CREATE OR REPLACE FUNCTION transaction_insert_check_close() RETURNS TRIGGER AS $transaction_insert_check_close$
BEGIN
IF (NEW.tr_type = 55) THEN
PERFORM pg_notify('check_close', to_char(NEW.n_transaction, 999999));
END IF;
RETURN NEW;
END;
$transaction_insert_check_close$ LANGUAGE plpgsql;