Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id D5F2F63404C for ; Tue, 22 Jun 2010 20:16:35 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 55458-03 for ; Tue, 22 Jun 2010 23:16:28 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wy0-f174.google.com (mail-wy0-f174.google.com [74.125.82.174]) by mail.postgresql.org (Postfix) with ESMTP id 76F4D63232D for ; Tue, 22 Jun 2010 20:16:28 -0300 (ADT) Received: by wyi11 with SMTP id 11so316864wyi.19 for ; Tue, 22 Jun 2010 16:16:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=842dFZa27/+WKT3XmrMcZb6MOBvkbhmDWyIWj/feaC8=; b=Br0iBA3/l5CLIizFxXnHsx2nRWIo+RnTaRaiNujpDSUQILbV62yf13ClSkpEaMMnBb V3lv6MOktS7yKvTxPHaZXGw5i7KeWlJ0ayw/1XYCEFmJvFrx3sTfbaWSmnryjYUinI5t lW9isva87Vxj3cTF8twsJfVvIb2OZFAVjZbFY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=KneIg2J9oMIEdO0sTE29ntROvy+pHfOMsQs9yzSi49G88DDWgrscAtiaGEbCUznu+j Vm6Bisz0YULhGHUyGfdiWN3qETYsp2w4vV+9bM8V6XPaZofHSEjRwubl4s4snovxjk1T /OWojFOnnpnRtogNKwHERhJvJJFAc9gItVcMI= Received: by 10.216.86.195 with SMTP id w45mr5260355wee.47.1277248586211; Tue, 22 Jun 2010 16:16:26 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.231.221 with HTTP; Tue, 22 Jun 2010 16:16:06 -0700 (PDT) In-Reply-To: <20100622230754.GE15203@fetter.org> References: <4C207403.3080103@gmail.com> <20100622230754.GE15203@fetter.org> From: Thom Brown Date: Wed, 23 Jun 2010 00:16:06 +0100 Message-ID: Subject: Re: INTEGER range ("-2147483648" is not accepted.) To: David Fetter Cc: Satoshi Nagayasu , pgsql-docs@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201006/56 X-Sequence-Number: 5624 On 23 June 2010 00:07, David Fetter wrote: > On Tue, Jun 22, 2010 at 09:36:30AM +0100, Thom Brown wrote: >> 2010/6/22 Satoshi Nagayasu : >> > Hi all, >> > >> > I've found a bit strange thing on the INTEGER range in the official ma= nual. >> > >> > http://www.postgresql.org/docs/8.4/interactive/datatype-numeric.html >> > >> > According to the official manual, the INTEGER range is "-2147483648 to= +2147483647". >> > However, my example in below shows that "-2147483648" is not accepted. >> > >> > Is this correct? Any suggestions? >> > >> > Regards, >> > >> > --------------------------------------------------------------------- >> > template1=3D# SELECT version(); >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0version >> > ----------------------------------------------------------------------= -------------------------------------- >> > =A0PostgreSQL 8.4.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 4.= 1.2 20071124 (Red Hat 4.1.2-42), 32-bit >> > (1 row) >> > >> > template1=3D# SELECT -2147483647::integer; >> > =A0?column? >> > ------------- >> > =A0-2147483647 >> > (1 row) >> > >> > template1=3D# SELECT -2147483648::integer; >> > ERROR: =A0integer out of range >> > template1=3D# SELECT +2147483648::integer; >> > ERROR: =A0integer out of range >> > template1=3D# SELECT +2147483647::integer; >> > =A0?column? >> > ------------ >> > =A02147483647 >> > (1 row) >> > >> > template1=3D# >> > --------------------------------------------------------------------- >> > >> >> Hmm... yes, that's not what I'd expect either: >> >> postgres=3D# SELECT -32768::smallint; >> ERROR: =A0smallint out of range >> postgres=3D# SELECT -9223372036854775808::bigint; >> ERROR: =A0bigint out of range >> >> I think those min values are all out by 1. > > Nope. =A0Same problem. > > SELECT (-32768)::smallint; > =A0-32768 > > SELECT (-9223372036854775808)::bigint; > =A0-9223372036854775808 > > I agree that the appropriate error message should complain about the > actual error, which is that 32768, or 2147483648, or > 9223372036854775808, as the case may be, is out of range in the > positive direction. =A0Possibly the "hint" might mention that :: binds > tighter than - does. > Is that the right behaviour though? Shouldn't the signed value reach the cast step rather than the absolute value? Or maybe Postgres could implicitly accept -12345::integer to be (-12345)::integer. Is there a blocking reason as to why it must work this way? Am I asking too many questions? Was that last question necessary? Thom