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

From Fabien COELHO
Subject Re: [HACKERS] psql - add special variable to reflect the last querystatus
Date
Msg-id alpine.DEB.2.20.1709121909060.30961@lancre
Whole thread Raw
In response to Re: [HACKERS] psql - add special variable to reflect the last querystatus  (Fabien COELHO <coelho@cri.ensmp.fr>)
Responses Re: [HACKERS] psql - add special variable to reflect the last query status
List pgsql-hackers
Hello Tom,

>>> Yep, I thought I was optimistic:-) Can I add a special SQLSTATE for that
>>> situation where libpq did not report an error?
>> 
>> Meh.  If we're going to do that I think it might be better to hack
>> libpq itself to do so, ie, force PQresultErrorField(..., PG_DIAG_SQLSTATE)
>> to always return something.  But it seems like a hack either way.
>
> I would not have took the liberty to hack into libpq internals for such a 
> small front-end feature. However I agree that having libpq always return some 
> diagnostic, even if it means "something unclear happened, sorry not to be 
> very precise", would be better.

Here is an attempt at implementing your suggestions.

I added two error codes, which is debatable. One is used hardcoded by 
libpq if no diagnostic is found, and the other by psql if libpq returned 
something empty, which might happen if psql is linked with an older libpq, 
maybe. I do not know how to trigger such errors anyway, so this is rather 
academic.

I put back SetResultVariables function which is called twice, for SQL 
queries and the new descriptions. It worked out of the box with DECLARE 
which is just another SQL statement, so maybe I did not understood the 
cursor issue you were signaling...

-- 
Fabien.
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachment

pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] Clarification in pg10's pgupgrade.html step 10(upgrading standby servers)
Next
From: Emre Hasegeli
Date:
Subject: Re: [HACKERS] [PATCH] Improve geometric types