Re: Invalid (null) int8, can't convert to float8 - Mailing list pgsql-sql

From Tom Lane
Subject Re: Invalid (null) int8, can't convert to float8
Date
Msg-id 20699.985027478@sss.pgh.pa.us
Whole thread Raw
In response to Invalid (null) int8, can't convert to float8  (Tim Pizey <tim@paneris.co.uk>)
List pgsql-sql
Tim Pizey <tim@paneris.co.uk> writes:
> If there is a a record with a Null textid in the table then psql reports
> the error:
> Invalid (null) int8, can't convert to float8
> to a query of the form 
> select id from chapter where textid = 9057599501;

> It does seem as though the textid in the query needs to be large to
> produce the error.

This is actually being interpreted as

select id from chapter where textid = 9057599501::float8;

and then the parser decides it needs to convert textid to float8 and
perform a float8 '=' (which among other things means this query won't
use the index).  This happens because the parser is going to interpret
that undecorated numeric constant as either int4 or float8, and it's
too big for int4, so float8 gets picked.

We have had some discussions about teaching the parser to be smarter
about choosing the type of numeric constants depending on context,
but for now you need to force the issue:

select id from chapter where textid = 9057599501::int8;

If you want the index to be used then you'd better do this all the
time, not only for values that are too big to be int4.

BTW, the inability to convert an int8 NULL to float8 is a bug;
it's fixed in 7.1.
        regards, tom lane


pgsql-sql by date:

Previous
From: Tim Pizey
Date:
Subject: Invalid (null) int8, can't convert to float8
Next
From: Tom Lane
Date:
Subject: Re: What do I do with this error?