agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedINT8 / float casting question
4+ messages / 3 participants
[nested] [flat]
* INT8 / float casting question
@ 2014-10-31 14:58 Filip Rembiałkowski <filip.rembialkowski@gmail.com>
2014-10-31 15:15 ` Re: INT8 / float casting question ktm@rice.edu <ktm@rice.edu>
2014-10-31 15:29 ` Re: INT8 / float casting question Adrian Klaver <adrian.klaver@aklaver.com>
2014-10-31 15:45 ` Re: INT8 / float casting question Adrian Klaver <adrian.klaver@aklaver.com>
0 siblings, 3 replies; 4+ messages in thread
From: Filip Rembiałkowski @ 2014-10-31 14:58 UTC (permalink / raw)
To: pgsql-sql
psql.bin (9.3.4, server 9.3.5)
Type "help" for help.
dev=# select (2^63-1)::INT8;
ERROR: bigint out of range
Does it HAVE to be so?
http://en.wikipedia.org/wiki/9223372036854775807
Thanks
Filip
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: INT8 / float casting question
2014-10-31 14:58 INT8 / float casting question Filip Rembiałkowski <filip.rembialkowski@gmail.com>
@ 2014-10-31 15:15 ` ktm@rice.edu <ktm@rice.edu>
2 siblings, 0 replies; 4+ messages in thread
From: ktm@rice.edu @ 2014-10-31 15:15 UTC (permalink / raw)
To: Filip Rembiałkowski <filip.rembialkowski@gmail.com>; +Cc: pgsql-sql
On Fri, Oct 31, 2014 at 03:58:06PM +0100, Filip Rembiałkowski wrote:
> psql.bin (9.3.4, server 9.3.5)
> Type "help" for help.
>
> dev=# select (2^63-1)::INT8;
> ERROR: bigint out of range
>
>
> Does it HAVE to be so?
>
>
> http://en.wikipedia.org/wiki/9223372036854775807
>
> Thanks
> Filip
Yes:
http://www.postgresql.org/docs/9.3/static/datatype.html
Table 8-1:
bigint, aliases int8 - signed eight-byte integer
PostgreSQL does not have an unsigned integer type, since all the
SQL ones are signed.
Regards,
Ken
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: INT8 / float casting question
2014-10-31 14:58 INT8 / float casting question Filip Rembiałkowski <filip.rembialkowski@gmail.com>
@ 2014-10-31 15:29 ` Adrian Klaver <adrian.klaver@aklaver.com>
2 siblings, 0 replies; 4+ messages in thread
From: Adrian Klaver @ 2014-10-31 15:29 UTC (permalink / raw)
To: Filip Rembiałkowski <filip.rembialkowski@gmail.com>; pgsql-sql
On 10/31/2014 07:58 AM, Filip Rembiałkowski wrote:
> psql.bin (9.3.4, server 9.3.5)
> Type "help" for help.
>
> dev=# select (2^63-1)::INT8;
> ERROR: bigint out of range
>
> Does it HAVE to be so?
>
>
> http://en.wikipedia.org/wiki/9223372036854775807
It seems to be not a problem with the number but the exponentiation and
casting:
test=# create table bigint_test (int_fld int8);
CREATE TABLE
test=# insert into bigint_test values (9223372036854775807);
INSERT 0 1
test=# select * from bigint_test ;
int_fld
---------------------
9223372036854775807
test=# select 2^63-1;
?column?
----------------------
9.22337203685478e+18
(1 row)
test=# select (2^63-1)::int8;
ERROR: bigint out of range
>
>
>
> Thanks
> Filip
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: INT8 / float casting question
2014-10-31 14:58 INT8 / float casting question Filip Rembiałkowski <filip.rembialkowski@gmail.com>
@ 2014-10-31 15:45 ` Adrian Klaver <adrian.klaver@aklaver.com>
2 siblings, 0 replies; 4+ messages in thread
From: Adrian Klaver @ 2014-10-31 15:45 UTC (permalink / raw)
To: Filip Rembiałkowski <filip.rembialkowski@gmail.com>; pgsql-sql
On 10/31/2014 07:58 AM, Filip Rembiałkowski wrote:
> psql.bin (9.3.4, server 9.3.5)
> Type "help" for help.
>
> dev=# select (2^63-1)::INT8;
> ERROR: bigint out of range
>
>
>
>
>
> Does it HAVE to be so?
No, figured it out:
test=# select ((2^63-1)::numeric);
numeric
---------------------
9223372036854780000
is rounding up.
To get what you want:
test=# select (2^63::numeric-1)::int8;
int8
---------------------
9223372036854775807
(1 row)
>
>
> http://en.wikipedia.org/wiki/9223372036854775807
>
>
>
> Thanks
> Filip
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2014-10-31 15:45 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-10-31 14:58 INT8 / float casting question Filip Rembiałkowski <filip.rembialkowski@gmail.com>
2014-10-31 15:15 ` ktm@rice.edu <ktm@rice.edu>
2014-10-31 15:29 ` Adrian Klaver <adrian.klaver@aklaver.com>
2014-10-31 15:45 ` Adrian Klaver <adrian.klaver@aklaver.com>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox