1

请帮我纠正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=55tr_typeint。n_transaction 是int.

PostgreSQL 8.3.4

请帮忙!

4

1 回答 1

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;
于 2012-05-18T19:04:28.107 回答