1

Please help me to correct sql statement:

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));

I need to receive notification when row with tr_type=55 is added. tr_type is int. n_transaction is int.

Postgresql 8.3.4

Please help!

1
  • 1
    Please note that "tramsaction" is a reserved word. Naming a table "transaction" is a bad choice. Commented May 20, 2012 at 21:08

1 Answer 1

2

Try the following:

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.