Re: Adding comments to help understand psql hidden queries

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Greg Sabino Mullane <htamfids(at)gmail(dot)com>
Cc: Maiquel Grassi <grassi(at)hotmail(dot)com(dot)br>, David Christensen <david+pg(at)pgguru(dot)net>, Peter Eisentraut <peter(at)eisentraut(dot)org>, Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Adding comments to help understand psql hidden queries
Date: 2026-03-23 17:35:04
Message-ID: 3616299.1774287304@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Greg Sabino Mullane <htamfids(at)gmail(dot)com> writes:
> Going back through all the feedback and comments, plus having some time to
> think things through, I am including a new patch, v7, that greatly
> simplifies things, and only makes changes inside of describe.c. In the
> spirit of not letting the perfect be the enemy of the good, I'm not
> worrying at all about the number of stars, or the width, and simply adding
> a small consistent description at the top of each query. I also realized
> that having these queries show up in someone's server log could be quite
> confusing, so I had them output as part of the query itself. In other
> words, they show up in both psql -E and the server logs.

I like this proposal quite a lot. It seems like about the right level
of development/maintenance effort, and I think it provides a useful
increment of usability.

I have one slightly-orthogonal suggestion. I think that we should
make the header for generated queries be different from that used
for user queries in psql's logfile mode. Right now those are both
/******** QUERY *********/
I propose instead printing
/**** INTERNAL QUERY ****/
if it's a generated query.

I went through the 0007 patch and made some editorial changes
beyond that addition. I fixed a couple more internal queries
to have headers (now each PSQLexec in describe.c has one).
I also changed some of Greg's proposed headers in hopes of
improving uniformity. Notably, I didn't like that some of the
headers said "table" and some said "relation". I made them all
say "table", although you could certainly argue for the opposite.
This is all in-the-eye-of-the-beholder, so feel free to push back
on any changes you don't like.

For ease of review, v8-0001 attached is identical to Greg's 0007,
and v8-0002 is my proposed changes on top of that.

regards, tom lane

Attachment Content-Type Size
v8-0001-Add-comment-header-for-generated-SQL-inside-psql.patch text/x-diff 34.7 KB
v8-0002-Improve-comment-headers-for-generated-SQL-inside-.patch text/x-diff 16.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2026-03-23 17:43:31 Re: Read-only connection mode for AI workflows.
Previous Message Ashutosh Bapat 2026-03-23 16:39:45 Re: [PATCH] rewriteGraphTable: Fix missing RTEs in FROM clause by setting inFromCl=true