Get the string of the query that fired a trigger

安稳与你 提交于 2021-02-20 04:26:07

问题


I am creating a control table in a PostgreSQL database, this table should register the query that fired a trigger in a specific table. For instance

if I do

insert into employees('bob');

I would like to be able to capture the string 'insert into employees('bob');' inside a trigger associated with employees table. It doesn't matter if the trigger is before or after.


回答1:


Use the function current_query() in the trigger function.

insert into control_table(query_text) 
select current_query();

The trigger should be for each statement.



来源:https://stackoverflow.com/questions/54014901/get-the-string-of-the-query-that-fired-a-trigger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!