Re: Object IDs in Parse message

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Object IDs in Parse message
Дата
Msg-id 23808.1567605903@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Object IDs in Parse message  (Malcolm Matalka <mmatalka@gmail.com>)
Список pgsql-interfaces
Malcolm Matalka <mmatalka@gmail.com> writes:
> Tom Lane <tgl@sss.pgh.pa.us> writes:
>> However, I fail to see why a generic client would need to know that.
>> If you're hard-wiring OIDs into your code for anything beyond very
>> basic types like int4, you're probably doing it wrong.  Remember

> Ok, it wasn't clear to me if and when I should pass this data in.  I
> couldn't find any documentation for this translating to performance
> improvement, or addressing any possible errors due to ambiguity in
> types.  In general, should an interface no pass that information in on a
> Parse?  Is there a reason to do it?

You should only pass type OIDs if you know for sure what they should be,
which an interface library passing on a query generated elsewhere will
not know --- unless it provides an API for the caller to tell it.

The convention that seems to have evolved in places that lack such APIs
is to pass zeroes, and instruct human authors of queries that if the
server doesn't resolve the types of parameter placeholders the way they
want, force it with a cast in the text of the query, eg "$1::int8".
Otherwise you need to add some out-of-band notation for specifying the
types, plus a way to resolve that notation into numeric OIDs, and it's
all a giant pain in the rear for all concerned.

Passing zeroes is more workable than you might think, since the
server can correctly guess the type of a placeholder in a lot
of cases.  However, it might be best to avoid it if you intend
to pass parameter values in binary, since that will lose a lot
of the safety margin for detecting wrong guesses.

            regards, tom lane



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

Предыдущее
От: Dave Cramer
Дата:
Сообщение: Re: Object IDs in Parse message
Следующее
От: "Greg Sabino Mullane"
Дата:
Сообщение: DBD::Pg version 3.10.0 released