Re: [HACKERS] psql - add special variable to reflect the last query status - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [HACKERS] psql - add special variable to reflect the last query status
Date
Msg-id 4573.1504630454@sss.pgh.pa.us
Whole thread Raw
In response to Re: [HACKERS] psql - add special variable to reflect the last query status  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: [HACKERS] psql - add special variable to reflect the last querystatus
Re: [HACKERS] psql - add special variable to reflect the last querystatus
List pgsql-hackers
A few thoughts about this patch:

* I think the ERROR_CODE variable should instead be named SQLSTATE.
That is what the SQL standard calls this string, and it's also what
just about all our documentation calls it; see PG_DIAG_SQLSTATE
in libpq, or the SQLSTATE 'xxxxx' construct in pl/pgsql, or the
sqlstate attribute of an exception object in plpython, etc etc.

* I'm not exactly convinced that there's a use-case for STATUS
that's not covered as well or better by ERROR.  Client code that
looks at PQresStatus for anything beyond error/not-error is
usually doing that because it's library code that doesn't know
what kind of query it's working on.  It seems like a stretch that
a psql script would not know that.  Also, PQresultStatus memorializes
some legacy distinctions, like "fatal" vs "nonfatal" error, that
I think we'd be better off not exposing in psql scripting.

* It might be better if SQLSTATE and ERROR_MESSAGE were left
unchanged by a non-error query.  That would reduce the need to
copy them into other variables just because you needed to do
something else before printing them.  It'd save a few cycles too.

* Speaking of which, has anyone tried to quantify the performance
impact of this patch?  It might well be negligible, but I do not
think we should assume that without evidence.

* I wonder why you didn't merge this processing into ProcessResult,
instead of inventing an extra function (whose call site seems rather
poorly chosen anyhow --- what's the justification for not counting this
overhead as part of the query runtime?).  You could probably eliminate
the refactoring you did, since it wouldn't be necessary to recompute
AcceptResult's result that way.
        regards, tom lane



pgsql-hackers by date:

Previous
From: andres@anarazel.de (Andres Freund)
Date:
Subject: Re: [HACKERS] JIT compiling expressions/deform + inlining prototypev2.0
Next
From: Tom Lane
Date:
Subject: Re: [HACKERS] [COMMITTERS] pgsql: Add psql variables showing server version and psql version.