Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lK6sN-0005mN-75 for pgsql-bugs@arkaria.postgresql.org; Wed, 10 Mar 2021 22:00:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lK6sK-0005qH-Ou for pgsql-bugs@arkaria.postgresql.org; Wed, 10 Mar 2021 22:00:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lK6sK-0005nu-IS for pgsql-bugs@lists.postgresql.org; Wed, 10 Mar 2021 22:00:16 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lK6sE-00078I-H5 for pgsql-bugs@lists.postgresql.org; Wed, 10 Mar 2021 22:00:15 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 12AM08jo2218409; Wed, 10 Mar 2021 17:00:09 -0500 From: Tom Lane To: levi@leviaul.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16919: Unexpected precision loss in NUMERIC type during text cast, math operations In-reply-to: <16919-64fff49d97341054@postgresql.org> References: <16919-64fff49d97341054@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Wed, 10 Mar 2021 20:41:32 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2218407.1615413608.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 10 Mar 2021 17:00:08 -0500 Message-ID: <2218408.1615413608@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > Simple operations on NUMERIC, supposedly an arbitrary-precision type,=C2= =A0are > having unexpected results for me: > SELECT '12345678901234567890123456789012345678901234567890'::numeric= ; > -- expected 12345678901234567890123456789012345678901234567890 > -- got 12345678901234567890123456789012345678900000000000 [ raised eyebrow... ] Works for me: regression=3D# SELECT '12345678901234567890123456789012345678901234567890'= ::numeric; numeric = ---------------------------------------------------- 12345678901234567890123456789012345678901234567890 (1 row) I'm wondering which compiler and what build options you used. Also, your reference to mpz makes me doubt that this is a stock version of Postgres, so maybe you just have a home-grown bug. (There are some arbitrary decisions about precision of the results of numeric division, as well as the transcendental functions. But plain addition and multiplication should be exact, and of course just reading out a literal certainly should be.) regards, tom lane