Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

results of shift on integers

0 views
Skip to first unread message

Coniglio Sgabbiato

unread,
Sep 22, 2009, 6:07:15 AM9/22/09
to
Hi all, is it the behaviour shown below normal?
I mean, why 1::int << 32 and 1::bigint << 64 gives 1 instead to return
an error?

db_atm=# select (1::bigint << 64)-1 as test;
test
------
0
(1 row)

db_atm=# select (1::bigint << 63)-1 as test;
ERROR: bigint out of range

db_atm=# select (1::bigint << 62)-1 as test;
test
---------------------
4611686018427387903
(1 row)

db_atm=# select (1::int << 32)-1 as test;
test
------
0
(1 row)

db_atm=# select (1::int << 31)-1 as test;
ERROR: integer out of range

db_atm=# select (1::int << 30)-1 as test;
test
------------
1073741823
(1 row)

Coniglio Sgabbiato

unread,
Sep 22, 2009, 6:09:57 AM9/22/09
to
I understood now...

db_atm=# select (1::bigint << 64);
?column?
----------
1
(1 row)

db_atm=# select (1::bigint << 65);
?column?
----------
2
(1 row)

db_atm=# select (1::bigint << 66);
?column?
----------
4
(1 row)


Coniglio Sgabbiato ha scritto:

0 new messages