How to definitively determine whether a statement is a SELECT statement?

From: Ron Johnson <ronljohnsonjr(at)gmail(dot)com>
To: Pgsql-admin <pgsql-admin(at)lists(dot)postgresql(dot)org>
Subject: How to definitively determine whether a statement is a SELECT statement?
Date: 2026-08-31 16:06:39
Message-ID: CANzqJaA9uF7JEyqmJ6JVuoadnAqU2=56VXC7stqJeTdpm6ozFQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Sometimes, the developers add comments to the top of statements, and so we
see that in pg_stat_activity.query as seen in this example:

select query
from pg_stat_activity
where pid = 1054079;
query
----------------------------------------
-- Some comment written by the developer
SELECT blah blah FROM .blah

I could case-insensitively search pg_stat_activity.query for "SELECT " but
that will fail if there is a SELECT in the CTE or subquery of a DELETE or
UPDATE statement, and writing a parser to strip out all comments is a bit
too much effort for a simple query.

--
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message bertrand HARTWIG 2026-09-01 05:07:17 Re: How to definitively determine whether a statement is a SELECT statement?
Previous Message Gyanuba Gyanuba 2026-08-24 15:07:10 Re: Unused Indexes