Re: plpgsql trigger original query - Mailing list pgsql-general

From Pavel Stehule
Subject Re: plpgsql trigger original query
Date
Msg-id 162867790709141332n75fade31ra4e7abdc4b6426c@mail.gmail.com
Whole thread Raw
In response to plpgsql trigger original query  (Dan99 <power919@gmail.com>)
List pgsql-general
> 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

pgsql-general by date:

Previous
From: rihad
Date:
Subject: Inserting a timestamp in a "timestamp" column.
Next
From: Erik Jones
Date:
Subject: Re: Inserting a timestamp in a "timestamp" column.