Re: How do I get the SQL statement in a trigger? - Mailing list pgsql-general

From a
Subject Re: How do I get the SQL statement in a trigger?
Date
Msg-id tencent_1BB669D71C0472151E423D3E@qq.com
Whole thread Raw
In response to Re: How do I get the SQL statement in a trigger?  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: How do I get the SQL statement in a trigger?
List pgsql-general
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

pgsql-general by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: How do I get the SQL statement in a trigger?
Next
From: Pavel Stehule
Date:
Subject: Re: How do I get the SQL statement in a trigger?