Re: psql - add special variable to reflect the last query status

From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql - add special variable to reflect the last query status
Date: 2017-09-12 17:23:55
Message-ID: alpine.DEB.2.20.1709121909060.30961@lancre
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

Attachment Content-Type Size
psql-result-status-8.patch text/x-diff 16.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Emre Hasegeli 2017-09-12 17:30:44 Re: [PATCH] Improve geometric types
Previous Message Bruce Momjian 2017-09-12 17:19:22 Re: Clarification in pg10's pgupgrade.html step 10 (upgrading standby servers)