real - integer type cast in prepared statements

Started by Андрейabout 20 years ago2 messagesgeneral
Jump to latest
#1Андрей
andyk@softwarium.net

Hi!

Why when I prepare statement by parsing such query: 'SELECT * FROM
"test" WHERE "ind" < $1 + 1' ("ind" is of type REAL) $1 is interpreted
by backend as INTEGER? Parse completed successfully, but trying to bind
parameter as '20.20' resulted in "ERROR C22P02 Minvalid input syntax for
integer: "20.20" Fnumutils.c L98 Rpg_atoi"? I understand that it's
possible to make query like 'SELECT * FROM "test" WHERE "ind" < $1::real
+ 1', but at the query building time I can't know what type this column is!

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Андрей (#1)
Re: real - integer type cast in prepared statements

Andrei <andyk@softwarium.net> writes:

Why when I prepare statement by parsing such query: 'SELECT * FROM
"test" WHERE "ind" < $1 + 1' ("ind" is of type REAL) $1 is interpreted
by backend as INTEGER?

Because the context in which its type first has to be resolved is "$1 + 1",
and the "1" is INTEGER.

regards, tom lane