Postgresql – Passing Arguments from INSERT / UPDATE to Trigger

postgresql-9.2trigger

I need a help with a trigger, this trigger I need to pass a value that comes from the queue column in the asterisk.queue table.

CREATE TRIGGER gerarconf
AFTER INSERT OR UPDATE
ON asterisk.fila
FOR EACH ROW
EXECUTE PROCEDURE asterisk.registra_gerar_conf_fila('FILA','XXXXX');

In place of XXXX I need to pass the value of the queue column that came from the insert or update of the asterisk.queue table

Best Answer

Use NEW or OLD depending if you need the inserted or updated record.

Postgres documentation

When a PL/pgSQL function is called as a trigger, several special variables are created automatically in the top-level block. They are:

NEW
Data type RECORD; variable holding the new database row for INSERT/UPDATE operations in row-level triggers. This variable is unassigned in statement-level triggers and for DELETE operations.

OLD
Data type RECORD; variable holding the old database row for UPDATE/DELETE operations in row-level triggers. This variable is unassigned in statement-level triggers and for INSERT operations.

CREATE TRIGGER gerarconf
AFTER INSERT OR UPDATE
ON asterisk.fila
FOR EACH ROW
EXECUTE PROCEDURE asterisk.registra_gerar_conf_fila('FILA',NEW.column);