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 1hRfS3-0007dA-22 for pgsql-bugs@arkaria.postgresql.org; Fri, 17 May 2019 16:11:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hRfS1-00026m-Fq for pgsql-bugs@arkaria.postgresql.org; Fri, 17 May 2019 16:11:17 +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 1hRfS1-00020U-4w for pgsql-bugs@lists.postgresql.org; Fri, 17 May 2019 16:11:17 +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 1hRfRx-0005RJ-78 for pgsql-bugs@lists.postgresql.org; Fri, 17 May 2019 16:11:15 +0000 Received: from SMTP-NORAM01I.ASG.COM (localhost.localdomain [127.0.0.1]) by localhost (Email Security Appliance) with SMTP id 78C663F399E0_CDEDD1DB; Fri, 17 May 2019 16:11:09 +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 AD32A3F37929_CDEDD0CF; Fri, 17 May 2019 16:10:52 +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:10:52 -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:10:52 -0400 From: Kaleb Akalework To: Alvaro Herrera , "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: AQHVDMnol7iEJWY7mEe5htre4eFOBqZver/Q Date: Fri, 17 May 2019 16:10:52 +0000 Message-ID: <982ab3c88ea14f4593cc45b26acb44f6@asg.com> References: <15812-adda7f0f3359803c@postgresql.org> <20190517160211.GA27103@alvherre.pgsql> In-Reply-To: <20190517160211.GA27103@alvherre.pgsql> 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="iso-8859-1" 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:subject:date:message-id:references:in-reply-to:content-type:content-transfer-encoding:mime-version; s=SEAKey; bh=SmpR7u2vk2gSicF3esobhoDnnVSLMZvHeAx7S6fBRmE=; b=rvyUd8jmzgForHc8sTJZhqos2UYBiMtEeviSVICsx/BHSwqfabaib9BVNd+/JtCVEVrUTdRfxFWk64x8cyUOaqEaV3Fordk5xI7Uu/XDi1ExYZEQgvyzlD+pleVWYI5QvNBKfVopdq5eTildKqOxpt/V0E2UYtItXGCPMjIuaYs8orCvjGpAvuGP04vnLme2d9mwBCQ2C3E1F/ZqavoboGNj4tdLWRrck8m1eDYBc3mgUS4XE2AzrvKAZntgaIWjfOEImTZPL/6qqnKT4njQ43lcnfleUNGeFMLJbPm0VqeU6I2E4EiIY0eSCBNPAwWA8W3YlIFHyhdtWDRoAlpe3A== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi Alvaro, Thank you for getting back to me. Well that is not correct the column is de= fined as numeric(20,0) because we don't expect decimal numbers in the colum= n,=20 but operations on the value should not be dictated by the column definition= . My table has millions of rows and cannot change the table definition due = to number of rows and business purposes. The question is why is the result = of the operation dictated by the column definition?=20 If you just did select (3691635539999999999/10000000000) you would get the = correct result minus all the numbers after the decimal point SELECT (3691635539999999999/10000000000) "369163553" This seems to be bug, no? I have data centers with SQL Server and Oracle an= d they don't exhibit this behavior Thank you again for getting back to me quickly. Looking forward to hearing = from you Thank you Kaleb Akalework -----Original Message----- From: Alvaro Herrera =20 Sent: Friday, May 17, 2019 12:02 PM To: 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 *** 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 from=20 > test_table; Well, your column definition has room for zero decimal places, so I'm not s= ure this result is all that surprising. Maybe you should cast the column t= o one that has a few decimal places, say select bit_num::numeric(30,10) / 10000000000 from test_table; and see whe= ther that helps your case. -- =C1lvaro Herrera http://TOC.ASG.COM:8080/?dmVyPTEuMDAxJiY2Mj= A1YzY5ZWNiMmRjZTgwOD01Q0RFREIwOF82NDEyOV8yOTEwXzEmJjNkYTNlNmVlYTQ1MDQwMT0xM= jMyJiZ1cmw9aHR0cHMlM0ElMkYlMkZ3d3clMkUybmRRdWFkcmFudCUyRWNvbSUyRg=3D=3D PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services