Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hRfqO-0000R9-R0 for pgsql-bugs@arkaria.postgresql.org; Fri, 17 May 2019 16:36:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hRfqM-0002vK-41 for pgsql-bugs@arkaria.postgresql.org; Fri, 17 May 2019 16:36:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hRfqL-0002vD-SX for pgsql-bugs@lists.postgresql.org; Fri, 17 May 2019 16:36:25 +0000 Received: from smtp-noram01i.asg.com ([67.239.247.176]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hRfqI-0005yx-Si for pgsql-bugs@lists.postgresql.org; Fri, 17 May 2019 16:36:24 +0000 Received: from SMTP-NORAM01I.ASG.COM (localhost.localdomain [127.0.0.1]) by localhost (Email Security Appliance) with SMTP id 631D03F39A85_CDEE304B; Fri, 17 May 2019 16:36:20 +0000 (GMT) Received: from smtp-noram01.asg.com (mail.asg.com [10.5.18.183]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by SMTP-NORAM01I.ASG.COM (Sophos Email Appliance) with ESMTPS id D7F523F37B79_CDEE303F; Fri, 17 May 2019 16:36:19 +0000 (GMT) Received: from USAPFMAIL03V.asg.com (10.5.18.183) by USAPFMAIL03V.asg.com (10.5.18.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1591.10; Fri, 17 May 2019 12:36:19 -0400 Received: from USAPFMAIL03V.asg.com ([fe80::7969:8bfa:cf09:5920]) by USAPFMAIL03V.asg.com ([fe80::7969:8bfa:cf09:5920%2]) with mapi id 15.01.1591.016; Fri, 17 May 2019 12:36:19 -0400 From: Kaleb Akalework To: Andres Freund , Alvaro Herrera CC: "pgsql-bugs@lists.postgresql.org" Subject: RE: BUG #15812: Select statement of a very big number, with a division operator seems to round up. Thread-Topic: BUG #15812: Select statement of a very big number, with a division operator seems to round up. Thread-Index: AQHVDMnol7iEJWY7mEe5htre4eFOBqZvw2qA//++soA= Date: Fri, 17 May 2019 16:36:19 +0000 Message-ID: References: <15812-adda7f0f3359803c@postgresql.org> <20190517160211.GA27103@alvherre.pgsql> <20190517162415.dglkkfc54t6ctv3y@alap3.anarazel.de> In-Reply-To: <20190517162415.dglkkfc54t6ctv3y@alap3.anarazel.de> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.10.120.36] x-exclaimer-md-config: 5902c074-9711-4a94-8042-bf8180fde9c1 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-SASI-RCODE: 200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=asg.com; h=from:to:cc:subject:date:message-id:references:in-reply-to:content-type:content-transfer-encoding:mime-version; s=SEAKey; bh=Az4lGx6khi9Fma0eQD3AqtBnJYe/Lcr1B1ke2CcHgK0=; b=cEsFwFn546BfOIwkSFsRp4TZmznTg+y2w89CmdP25GDv9wsTLe5fo8XqC+2b8+ktg6dKH4V609z38Z/umprBsu4PWvlM3mmCnA22ApNNWA/QNVOIl4FTDBrz6jU2h/uLbK15tI5fwgeJAojCUCoAneiPRj/0PLNWbv1UHPXJZFguzIyKDDhYZFQcCi8GPB03bOAE0bv6F433ztC1RvAtXrCbonCsUpWi31rbTKH36vdrUrXr5Tb7w44cMz3guPV0AgRKgrnIE2goZT2ErdLDdzSx0BwporMU+Dx+hjqgB78JIm6BKcV07D0yiWpEPsrN3HiFQdlwXiN8De28bp6qeA== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, Thank you Alvaro, Andres and David.=20 I tried Andres suggestion in his last email and that seems to work as a wor= k around. Please see below.=20 SELECT BIG_NUM, FLOOR(BIG_NUM /10000000000.0000000000), BIG_NUM/1000000000= 0.0000000000 from test_table "3691635539999999999" "369163553" "369163553.9999999999" "3691635530099999999" "369163553" "369163553.0099999999" "3691635530999999999" "369163553" "369163553.0999999999" But should this be a bug? Can their a better support of this, instead of ha= ving the query writer to know how many decimal numbers to put to get the co= rrect type?=20 It seems a little awkward and error prone to have to type .0000.... etc? Thank you all again for the fast response. Kaleb Akalework -----Original Message----- From: Andres Freund =20 Sent: Friday, May 17, 2019 12:24 PM To: Alvaro Herrera Cc: Kaleb Akalework ; pgsql-bugs@lists.postgresql.= org Subject: Re: BUG #15812: Select statement of a very big number, with a divi= sion operator seems to round up. *** External email: Verify sender before opening attachments or links *** Hi, On 2019-05-17 12:02:11 -0400, Alvaro Herrera wrote: > On 2019-May-17, PG Bug reporting form wrote: > > > create table test_table > > ( > > REQUEST_UUID varchar(50) not null, > > BIG_NUM numeric(20,0) not null > > ); > > > > INSERT INTO test_table (REQUEST_UUID, BIG_NUM) values ('TEST',=20 > > 3691635539999999999); INSERT INTO test_table (REQUEST_UUID, BIG_NUM)=20 > > values('TEST', 3691635530099999999); INSERT INTO test_table=20 > > (REQUEST_UUID, BIG_NUM) values('TEST', 3691635530999999999); > > > > SELECT BIG_NUM, FLOOR(BIG_NUM/10000000000), BIG_NUM/10000000000=20 > > from test_table; > > Well, your column definition has room for zero decimal places, so I'm=20 > not sure this result is all that surprising. Maybe you should cast=20 > the column to one that has a few decimal places, say > select bit_num::numeric(30,10) / 10000000000 from test_table; and=20 > see whether that helps your case. Arguably it's less the column's and more the divisor's precision that's the= problem. Note that even if big_num were numeric (i.e. without an implied p= recision) you'd get the OP's results - the precision is not "widened" to th= e appropriate width for the max precision needed for the division. Greetings, Andres Freund