| From: | Pierre Frédéric Caillaud <lists(at)peufeu(dot)com> | 
|---|---|
| To: | "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org> | 
| Subject: | integer input functions : interesting limit behaviour | 
| Date: | 2009-09-08 11:15:28 | 
| Message-ID: | op.uzxqv2grcke6l8@soyouz | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
I was looking in the int*in() functions and found some interesting limit  
behaviours :
* Here, the most negative value is sometimes accepted, sometimes not :
test=> SELECT -2147483648::INTEGER;
ERREUR:  entier en dehors des limites
test=> SELECT '-2147483648'::INTEGER;
     int4
-------------
  -2147483648
* Same for smallint :
test=> SELECT -32768::SMALLINT;
ERREUR:  smallint en dehors des limites
test=> SELECT '-32768'::SMALLINT;
   int2
--------
  -32768
(1 ligne)
* For BIGINT :
test=> SELECT -9223372036854775808::BIGINT;
ERREUR:  bigint en dehors des limites
test=> SELECT '-9223372036854775808'::BIGINT;
          int8
----------------------
  -9223372036854775808
(1 ligne)
Temps : 0,185 ms
test=> SELECT '-000000009223372036854775808'::BIGINT;
ERREUR:  la valeur « -000000009223372036854775808 » est en dehors des  
limites du type bigint
Interesting, isn't it ?
I guess it's good to reject -2147483648::INTEGER because this is ugly :
test=> CREATE TABLE foo AS (SELECT '-2147483648'::INTEGER AS x);
test=> SELECT -x FROM foo;
ERREUR:  entier en dehors des limites
I can make a fix...
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Stuart Bishop | 2009-09-08 11:16:34 | Re: Time-based Releases WAS: 8.5 release timetable, again | 
| Previous Message | Jan Otto | 2009-09-08 10:57:22 | Re: More Snow Leopard fun: multiarch problems while building plperl |