Postgresql触发器通知

时间:2012-05-18 18:57:33

标签: sql postgresql

请帮我纠正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_typeint。 n_transaction是int

Postgresql 8.3.4

请帮忙!

1 个答案:

答案 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;