pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: a <372660931@qq.com>
To: Pavel Stehule <pavel.stehule@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: How do I get the SQL statement in a trigger?
Date: Thu, 10 May 2018 18:42:22 +0800
Message-ID: <tencent_1BB669D71C0472151E423D3E@qq.com> (raw)
In-Reply-To: <CAFj8pRDiooLRVsfTe9JOzrCyL4c6D1ad5b=1NAvxLkMDw=93sg@mail.gmail.com>
References: <tencent_6EF46BDD28A4F2AA52209B4B@qq.com>
	<CAFj8pRDiooLRVsfTe9JOzrCyL4c6D1ad5b=1NAvxLkMDw=93sg@mail.gmail.com>

Thanks a lot, would you please be so kind to tell me more about what is top level query??




------------------ Original message ------------------
From: "Pavel Stehule"; 
Sendtime: Thursday, May 10, 2018 6:38 PM
To: "a"<372660931@qq.com>; 
Cc: "pgsql-general"; 
Subject: Re: How do I get the SQL statement in a trigger?



Hi

2018-05-10 12:23 GMT+02:00 a <372660931@qq.com>:
Hi I would like to write a trigger that recorded every sql statement under the effected entry. So if it is possible to retrieve the sql statement within a trigger??


You can read a tom command from pg_stat_activity table

 postgres=# select query from pg_stat_activity where pid = pg_backend_pid();
+------------------------------------------------------------------+
|                              query                               |
+------------------------------------------------------------------+
| select query from pg_stat_activity where pid = pg_backend_pid(); |
+------------------------------------------------------------------+
(1 row)


But this information is available only for top level query. 


Regards


Pavel

view thread (6+ messages)  latest in thread

Message-ID: <tencent_1BB669D71C0472151E423D3E@qq.com>
Permalink:  ../tencent_1BB669D71C0472151E423D3E@qq.com/
Also on:    postgresql.org/message-id/tencent_1BB669D71C0472151E423D3E@qq.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: 372660931@qq.com, pavel.stehule@gmail.com
  Subject: Re: How do I get the SQL statement in a trigger?
  In-Reply-To: <tencent_1BB669D71C0472151E423D3E@qq.com>
  References: <tencent_6EF46BDD28A4F2AA52209B4B@qq.com> <CAFj8pRDiooLRVsfTe9JOzrCyL4c6D1ad5b=1NAvxLkMDw=93sg@mail.gmail.com> <tencent_1BB669D71C0472151E423D3E@qq.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox