Re: Invalid (null) int8, can't convert to float8

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Tim Pizey <tim(at)paneris(dot)co(dot)uk>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Invalid (null) int8, can't convert to float8
Date: 2001-03-19 18:44:38
Message-ID: 20699.985027478@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Tim Pizey <tim(at)paneris(dot)co(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2001-03-19 19:04:13 Re: What do I do with this error?
Previous Message Tom Lane 2001-03-19 17:46:39 Re: What do I do with this error?