pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedInvalid (null) int8, can't convert to float8
3+ messages / 2 participants
[nested] [flat]
* Invalid (null) int8, can't convert to float8
@ 2001-03-19 17:27 Tim Pizey <tim@paneris.co.uk>
0 siblings, 1 reply; 3+ messages in thread
From: Tim Pizey @ 2001-03-19 17:27 UTC (permalink / raw)
To: pgsql-sql
Hi,
I have been lurking for a while and am very appreciative of the effort
put in by the answers on this list, and for psql itself.
I am using Postgres version 7.0.2
I have a table defined thus:
CREATE TABLE "chapter" (
"id" int4 NOT NULL,
"book" int4 NOT NULL,
"sequence" int4 NOT NULL,
"textid_old" int4,
"indexdate" timestamp,
"title" text NOT NULL,
"path" text NOT NULL,
"filename" text NOT NULL,
"part" text,
"lastencached" timestamp,
"longtitle" text,
"layout" int4,
"messageboard" int4,
"textid" int8
);
CREATE UNIQUE INDEX "chapter_id_index" on "chapter" using btree ( "id"
"int4_ops" );
CREATE INDEX "chapter_book_index" on "chapter" using btree ( "book"
"int4_ops" );
CREATE INDEX "chapter_sequence_index" on "chapter" using btree (
"sequence"
"int4_ops" );
CREATE UNIQUE INDEX "chapter_textid_index" on "chapter" using btree (
"textid" "int8_ops" );
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.
Can anyone suggest what is going on?
I have, temporary, fixed the problem by eliminating all records with a
null textid, but
null is a sensible value, so it will re-occur.
thanks in advance
timp
--
Member of http://www.paneris.org/
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Invalid (null) int8, can't convert to float8
@ 2001-03-19 18:44 Tom Lane <tgl@sss.pgh.pa.us>
parent: Tim Pizey <tim@paneris.co.uk>
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2001-03-19 18:44 UTC (permalink / raw)
To: Tim Pizey <tim@paneris.co.uk>; +Cc: 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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Invalid (null) int8, can't convert to float8
@ 2001-03-20 00:40 Tim Pizey <tim@paneris.co.uk>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 3+ messages in thread
From: Tim Pizey @ 2001-03-20 00:40 UTC (permalink / raw)
To: ; +Cc: pgsql-sql
Thanks a lot Tom,
Tom Lane wrote:
>
> Tim Pizey <tim@paneris.co.uk> writes:
> 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.
>
This problem is actually happening through jdbc, using
PreparedStatements,
shouldn't jdbc be able to deal with casting transparently?
I am calling this with a string "chapter = ?" which automatically quotes
and escapes string values correctly.
Hope this isn't too wrong
timp
--
Member of http://www.paneris.org/
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2001-03-20 00:40 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-03-19 17:27 Invalid (null) int8, can't convert to float8 Tim Pizey <tim@paneris.co.uk>
2001-03-19 18:44 ` Tom Lane <tgl@sss.pgh.pa.us>
2001-03-20 00:40 ` Tim Pizey <tim@paneris.co.uk>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox