Re: Confusion over Python drivers

Поиск
Список
Период
Сортировка
От Andrew McNamara
Тема Re: Confusion over Python drivers
Дата
Msg-id 20100209065354.E51D5206F9@longblack.object-craft.com.au
обсуждение исходный текст
Ответ на Re: Confusion over Python drivers  (Jeff Davis <pgsql@j-davis.com>)
Ответы Re: Confusion over Python drivers  ("Greg Sabino Mullane" <greg@turnstep.com>)
Список pgsql-hackers
>If the date is passed in binary format, it will pass it to int4recv() --
>but because the date is 4 bytes, and int4recv is defined for any 4-byte
>input, it won't cause an error; it will produce a wrong result. In other
>words, the binary representation for a date _is_ a valid binary
>representation for an integer. The type inference has found the wrong
>type, but the recv function still accepts it, which causes a problem.

Yes - of the worst kind: silent data corruption.

>The solution is to write the query in an unambiguous way:
>
>  SELECT $1::date + 1;
>
>which is good practice, anyway. If it's not obvious to the type
>inference system, it's probably not obvious to you, and will probably
>surprise you ;)

That address this specific case, but it's ugly and not general. The right
thing is to set the correct type when you're marshalling the parameters...

>Or, as Andrew suggests, you can pass the type oid along with the
>parameter so that postgresql knows the right type.

That's right - if using the binary parameters, you *must* pass an
appropriate type oid for the data you send to the server. If you use the
"unknown" oid, bad things will happen (sooner or later).

While this is strictly true of both binary and text parameters, text
parameters have enough redundancy built into the format that it's rarely
a problem. Users have come to expect this leniency.

-- 
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/


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

Предыдущее
От: Jeff Davis
Дата:
Сообщение: Re: Listen / Notify - what to do when the queue is full
Следующее
От: Michael Meskes
Дата:
Сообщение: Re: buildfarm breakage