Re: making the backend's json parser work in frontend code

Поиск
Список
Период
Сортировка
От Michael Paquier
Тема Re: making the backend's json parser work in frontend code
Дата
Msg-id 20200116033528.GC3117@paquier.xyz
обсуждение исходный текст
Ответ на Re: making the backend's json parser work in frontend code  (Robert Haas <robertmhaas@gmail.com>)
Список pgsql-hackers
On Wed, Jan 15, 2020 at 09:39:13PM -0500, Robert Haas wrote:
> On Wed, Jan 15, 2020 at 6:40 PM Andres Freund <andres@anarazel.de> wrote:
>> It's not obvious why the better approach here wouldn't be to just have a
>> very simple ereport replacement, that needs to be explicitly included
>> from frontend code. It'd not be meaningfully harder, imo, and it'd
>> require fewer adaptions, and it'd look more familiar.
>
> I agree that it's far from obvious that the hacks in the patch are
> best; to the contrary, they are hacks. That said, I feel that the
> semantics of throwing an error are not very well-defined in a
> front-end environment. I mean, in a backend context, throwing an error
> is going to abort the current transaction, with all that this implies.
> If the frontend equivalent is to do nothing and hope for the best, I
> doubt it will survive anything more than the simplest use cases. This
> is one of the reasons I've been very reluctant to go do down this
> whole path in the first place.

The error handling is a well defined concept in the backend.  If
connected to a database, you know that a session has to rollback any
existing activity, etc.  The clients have to be more flexible because
an error depends a lot of how the tools is designed and how it should
react on a error.  So the backend code in charge of logging an error
does the best it can: it throws an error, then lets the caller decide
what to do with it.  I agree with the feeling that having a simple
replacement for ereport() in the frontend would be nice, that would be
less code churn in parts shared by backend/frontend.

> Not sure how. pg_mblen() and PQmblen() are both existing interfaces,
> and they're not compatible with each other. I guess we could make
> PQmblen() available to backend code, but given that the function name
> implies an origin in libpq, that seems wicked confusing.

Well, the problem here is the encoding part, and the code looks at the
same table pg_wchar_table[] at the end, so this needs some thoughts.
On top of that, we don't know exactly on the client what kind of
encoding is available (this led for example to several
assumptions/hiccups behind the implementation of SCRAM as it requires
UTF-8 per its RFC when working on the libpq part).
--
Michael

Вложения

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

Предыдущее
От: Michael Paquier
Дата:
Сообщение: Re: Setting min/max TLS protocol in clientside libpq
Следующее
От: Michael Paquier
Дата:
Сообщение: Re: isTempNamespaceInUse() is incorrect with its handling ofMyBackendId