Re: Access last_sqlstate from libpq

Поиск
Список
Период
Сортировка
От Daniel Frey
Тема Re: Access last_sqlstate from libpq
Дата
Msg-id AAC73528-F852-4FEA-B336-66DBCED46AC9@gmx.de
обсуждение исходный текст
Ответ на Re: Access last_sqlstate from libpq  ("David G. Johnston" <david.g.johnston@gmail.com>)
Ответы Re: Access last_sqlstate from libpq  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-hackers
> On 18. Sep 2021, at 01:45, David G. Johnston <david.g.johnston@gmail.com> wrote:
>
>
>
> On Friday, September 17, 2021, Daniel Frey <d.frey@gmx.de> wrote:
>
> However, this is not possible in a couple of other cases where I don't have a PGresult*, only the PGconn* is
available:
>
> * PQconnectdb (and variants)
>
> * PQputCopyData
> * PQputCopyEnd
> * PQgetCopyData
>
> * lo_* (large object functions)
>
> After some research, it appears that PGconn* does have a field called last_sqlstate - it just can't be accessed.
> Are there any problems adding a simple accessor to libpq? Or is there some way to access it that I'm missing?
>
> I suspect the reason for the omission is that there isn’t any usable data to be gotten.  Those interfaces are not SQL
interfacesand thus do not have a relevant last_sqlstate to report. 
>
> David J.

Are you sure or are you guessing? It appears that for PQconnectdb there are a couple of SQLSTATES defined which could
helpusers. The 08 Class "Connection Exception" contains at least 08001, 08004, 08P01 which could be helpful for users.
ForPGputCopyData, etc. Class 22 contains a lot of states that could explain what went wrong (in case it's the data),
otherstates potentially also apply (like when the connection is lost, etc.). Even for large data it might me helpful to
seestates that indicate if the server ran out of disk space, etc. 

Maybe not all of this is currently implemented (i.e. a reasonable SQLSTATE is stored in last_sqlstate), but I would
hopethat it is in some cases. 

Daniel




В списке pgsql-hackers по дате отправления:

Предыдущее
От: Alexander Korotkov
Дата:
Сообщение: Re: postgres.h included from relcache.h - but removing it breaks pg_upgrade
Следующее
От: Andres Freund
Дата:
Сообщение: Re: postgres.h included from relcache.h - but removing it breaks pg_upgrade