Re: psql - factor out echo code

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: Shinya11(dot)Kato(at)nttdata(dot)com, PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: psql - factor out echo code
Date: 2021-07-02 15:15:54
Message-ID: 819253.1625238954@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr> writes:
> [ psql-echo-2.patch ]

I went to commit this, figuring that it was a trivial bit of code
consolidation, but as I looked around in common.c I got rather
unhappy with the inconsistent behavior of things. Examining
the various places that implement "echo"-related logic, we have
the three places this patch proposes to unify, which log queries
using

fprintf(out,
_("********* QUERY **********\n"
"%s\n"
"**************************\n\n"), query);

and then we have two more that just do

puts(query);

plus this:

if (!OK && pset.echo == PSQL_ECHO_ERRORS)
pg_log_info("STATEMENT: %s", query);

So it's exactly fifty-fifty as to whether we add all that decoration
or none at all. I think if we're going to touch this logic, we
ought to try to unify the behavior. My vote would be to drop the
decoration everywhere, but perhaps there are votes not to?

A different angle is that the identical decoration is used for both
psql-generated queries that are logged because of ECHO_HIDDEN, and
user-entered queries. This seems at best rather unhelpful. If
we keep the decoration, should we make it different for those two
cases? (Maybe "INTERNAL QUERY" vs "QUERY", for example.) The
cases with no decoration likewise fall into multiple categories,
both user-entered and generated-by-gexec; if we were going with
a decorated approach I'd think it useful to make a distinction
between those, too.

Thoughts?

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2021-07-02 15:20:17 Re: Preventing abort() and exit() calls in libpq
Previous Message Alvaro Herrera 2021-07-02 14:59:33 Re: Preventing abort() and exit() calls in libpq