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 1hRffO-0008Ig-3n for pgsql-bugs@arkaria.postgresql.org; Fri, 17 May 2019 16:25:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hRffM-0001t3-P0 for pgsql-bugs@arkaria.postgresql.org; Fri, 17 May 2019 16:25:04 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hRfee-0007C0-0V for pgsql-bugs@lists.postgresql.org; Fri, 17 May 2019 16:24:20 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hRfeb-00017k-Kb for pgsql-bugs@lists.postgresql.org; Fri, 17 May 2019 16:24:18 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id EAB9A231A5; Fri, 17 May 2019 12:24:16 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 17 May 2019 12:24:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=YokUGwhXE/zvrDBpx1JIRda9gZ1 4bPsxb6eWgHgBcnk=; b=GCqemW1DMBEi6McSnWWUDdd1n7jd9jQcjIHc04DPnUY HpPt/p+wLyXH0COa8IC2m21f1f1f54FdEjLHF8r0bWfE4GJxQq+++Fb9neJy6wC1 SL0cnBJEB+zVCNH6PcaOqnTUTOilV/TGWvP9+MND4Crs4bU4wTNhot947x93jc7M W2Civ+6Lak3YMqmKq5fCXj/YA5lxNDX8ZVx/LtFxfpFF4oYJ6tv5VDrzI6jfRpfm FvWFRMQVGmnbdnyLUJXr8uK4xB3xHZsg0AnVraXH962IG38kKgls2b6gz9c94mp/ KHpOe+o8Qiapr0WGZ+w/86N/vOxo3Y4/v6NmFEKviNA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=YokUGw hXE/zvrDBpx1JIRda9gZ14bPsxb6eWgHgBcnk=; b=XC5hCeTx0H7XBWpU900Yfj hw/zE1Fi9m5dL/rr7kVwo2ZZgrTBQGJ5rOn3v6XFTcFz551yJe1HJjYSpTtgyojT OBNi0oa0s9jqDf/iGM2NYQ1ztJHT/hjpzPQkR0QhiY/POMg+rkKYDTlwNtcDPvEP I/yYSCJACl9wSOoDQDcPgUC1JrFI8eJ9IZUnq8bmAc1+EaVgWS6CdvruoNN8JdLv yvotzsn3m2fxEKYi07KFp++OJ1WDvwPkvQzmKwPQEhm+6yyxpZSHHVIvgqmcgMgO 1ZrDv/4lPirgxoIIjv5QOM+teWFLDqnW6vEGGdNNt1HEnK2HTC7Hxwr787DXK4Uw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddruddtvddguddtvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvuffkfhggtggujgesthdtredttddtvdenucfhrhhomheptehnughr vghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecukfhppe elkedrvddutddrudegtddrudejudenucfrrghrrghmpehmrghilhhfrhhomheprghnughr vghssegrnhgrrhgriigvlhdruggvnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from intern.anarazel.de (c-98-210-140-171.hsd1.ca.comcast.net [98.210.140.171]) by mail.messagingengine.com (Postfix) with ESMTPA id 52C088005A; Fri, 17 May 2019 12:24:16 -0400 (EDT) Date: Fri, 17 May 2019 09:24:15 -0700 From: Andres Freund To: Alvaro Herrera Cc: kaleb.akalework@asg.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15812: Select statement of a very big number, with a division operator seems to round up. Message-ID: <20190517162415.dglkkfc54t6ctv3y@alap3.anarazel.de> References: <15812-adda7f0f3359803c@postgresql.org> <20190517160211.GA27103@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190517160211.GA27103@alvherre.pgsql> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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', > > 3691635539999999999); > > INSERT INTO test_table (REQUEST_UUID, BIG_NUM) values('TEST', > > 3691635530099999999); > > INSERT INTO test_table (REQUEST_UUID, BIG_NUM) values('TEST', > > 3691635530999999999); > > > > SELECT BIG_NUM, FLOOR(BIG_NUM/10000000000), BIG_NUM/10000000000 from > > test_table; > > Well, your column definition has room for zero decimal places, so I'm > not sure this result is all that surprising. Maybe you should cast the > column to one that has a few decimal places, say > select bit_num::numeric(30,10) / 10000000000 from test_table; > and 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 precision) you'd get the OP's results - the precision is not "widened" to the appropriate width for the max precision needed for the division. Greetings, Andres Freund