| From: | Maciej Sakrejda <m(dot)sakrejda(at)gmail(dot)com> |
|---|---|
| To: | pgsql-general(at)postgresql(dot)org |
| Subject: | cast question: max double precision > text > double precision fails with out or range error |
| Date: | 2011-01-08 02:11:28 |
| Message-ID: | AANLkTinQDgexxj4=zjPRifUrvdf5bGw7RDgoes0yUZs+@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
postgres=# select (((1.7976931348623157081e+308)::double
precision)::text)::double precision;
ERROR: "1.79769313486232e+308" is out of range for type double precision
I can't think of too many practical use cases here, but I'm working on
a pg driver and in my float data decoder functional tests, I ran into
some errors that I eventually traced back to this behavior.
Essentially, postgres seems to cast the max normal double (i.e., the
bits of ~(1ULL<<52 | 1ULL<<63)) to text in such a manner that it's
rounded up, and the reverse cast, text-to-double-precision, does not
recognize it as being in range. Is this just a case of "don't do
that"? Curiously, pg_dump seems to print doubles with more precision
(in both COPY and INSERT modes), avoiding this issue. Of course I'm
not expecting perfect precision in round-tripping doubles like this
(this is always dicey with IEEE floating point anyway), but failing
outright is a little ugly. Any thoughts? Version is PostgreSQL 8.4.6
on i486-pc-linux-gnu, compiled by GCC gcc-4.4.real (Ubuntu
4.4.3-4ubuntu5) 4.4.3, 32-bit.
Thanks,
Maciek Sakrejda
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Jasen Betts | 2011-01-08 10:48:24 | Re: UUID column as pimrary key? |
| Previous Message | Oliver Kohll - Mailing Lists | 2011-01-07 22:21:42 | Re: Realtime Query Dashboard Results |