Re: plpgsql trigger original query

From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: Dan99 <power919(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: plpgsql trigger original query
Date: 2007-09-14 20:32:36
Message-ID: 162867790709141332n75fade31ra4e7abdc4b6426c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Erik Jones 2007-09-14 20:36:13 Re: Inserting a timestamp in a "timestamp" column.
Previous Message rihad 2007-09-14 20:23:47 Inserting a timestamp in a "timestamp" column.