plpgsql trigger original query
Hi,
I am looking for a way to get the original query that caused a trigger
to fire. I need to be able to get this query either inside the
trigger itself (and then send it to the function the trigger calls) or
get it in the end function. Is this doable? The reason i am asking is
that I would like to be able to send a variable (this variable would
come from php where the original query is executed) to the end
function called by the trigger.
Any help with this would be greatly appreciated.
Thanks,
Dan
Hi,
I am looking for a way to get the original query that caused a trigger
to fire. I need to be able to get this query either inside the
trigger itself (and then send it to the function the trigger calls) or
get it in the end function. Is this doable? The reason i am asking is
that I would like to be able to send a variable (this variable would
come from php where the original query is executed) to the end
function called by the trigger.Any help with this would be greatly appreciated.
Thanks,
Dan
currently this feature isn't supported. You can look to
pg_stat_activity table for top outer statement:
create or replace function current_statement()
returns varchar as $$
select current_query from pg_stat_activity where procpid = pg_backend_pid();
$$ language sql;
postgres=# select now(), current_statement();
now | current_statement
----------------------------+------------------------------------
2007-09-14 22:29:58.285+02 | select now(), current_statement();
(1 row)
Regards
Pavel Stehule