M
M
Melnik2282021-04-03 16:40:37
PostgreSQL
Melnik228, 2021-04-03 16:40:37

Are there variables like NEW and OLD in statement level triggers?

NEW
Data type RECORD. The variable contains the new database row for INSERT/UPDATE commands in row-level triggers. In statement-level triggers and for the DELETE command, this variable is not assigned a value.

OLD
Data type RECORD. The variable contains the old database row for UPDATE/DELETE commands in row level triggers. In statement-level triggers and for the INSERT statement, this variable is not assigned a value.

is there something similar for operator level triggers? so that all the affected lines are stored in some variable?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2021-04-03
@galaxy

Yes, for AFTER STATEMENT triggers there is :

CREATE TRIGGER transfer_insert
    AFTER UPDATE ON transfer
    REFERENCING NEW TABLE AS newtab OLD TABLE AS oldtab
    FOR EACH STATEMENT
    EXECUTE FUNCTION check_transfer_balances_to_zero();

In the check_transfer_balances_to_zero function, the newtab and oldtab tables will be available.
(According to the documentation, REFERENCING can also be specified for ROW triggers. I don’t know how it works in this case)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question