I have a trigger that executes before delete to audit changes in tables. The problem I have is that one of the fields I save in the xtable_audit
table is the user id (of an user table) that is used in the web application. How can I send that external iduser
from the web application to the trigger function when a delete occurs in any table that has that trigger?
Postgresql – How to send a parameter to a trigger function from an external resource
plpgsqlpostgresqltrigger
Related Question
- PostgreSQL Trigger Function: Selecting from Current Table
- PostgreSQL – Using Trigger Function with Current Row and Table Name
- Postgresql – Use array of composite type as function parameter and access it
- Postgresql – Insert trigger function from select query, plus static values pulled from the new.
- PostgreSQL Trigger Function Error – Missing FROM-clause Entry for Table
- Postgresql – Accessing old version of referenced table in trigger function – Postgresql
- PostgreSQL – Case Insensitive Column Names in Trigger Function
Best Answer
You could use the
set_config()
andcurrent_setting()
functions for that. In the application just after establishing the database connection you call something liketo set a custom configuration variable for the session. In the trigger you then use
to retrieve the value.
This blog post even has a sample trigger for your viewing pleasure.