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 1m2ETn-0003Lb-L0 for pgsql-committers@arkaria.postgresql.org; Sat, 10 Jul 2021 15:01: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 1m2ETl-0005a4-Dy for pgsql-committers@arkaria.postgresql.org; Sat, 10 Jul 2021 15:01:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m2ETl-0005Zw-8I for pgsql-committers@lists.postgresql.org; Sat, 10 Jul 2021 15:01:17 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m2ETj-00068H-8v for pgsql-committers@lists.postgresql.org; Sat, 10 Jul 2021 15:01:16 +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 16AF1CV92387729; Sat, 10 Jul 2021 11:01:12 -0400 From: Tom Lane To: Dean Rasheed cc: pgsql-committers@lists.postgresql.org Subject: Re: pgsql: Fix numeric_mul() overflow due to too many digits after decimal In-reply-to: References: Comments: In-reply-to Dean Rasheed message dated "Sat, 10 Jul 2021 11:54:15 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2387727.1625929272.1@sss.pgh.pa.us> Date: Sat, 10 Jul 2021 11:01:12 -0400 Message-ID: <2387728.1625929272@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Dean Rasheed writes: > This fixes an overflow error when using the numeric * operator if the > result has more than 16383 digits after the decimal point by rounding > the result. Overflow errors should only occur if the result has too > many digits *before* the decimal point. I think this needs a bit more thought. Before, a case like select 1e-16000 * 1e-16000; produced ERROR: value overflows numeric format Now you get an exact zero (with a lot of trailing zeroes, but still it's just zero). Doesn't that represent catastrophic loss of precision? In general, I'm disturbed that we just threw away the previous promise that numeric multiplication results were exact. That seems like a pretty fundamental property --- which is stated in so many words in the manual, btw --- and I'm not sure I want to give it up. regards, tom lane