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 1m2GoR-0007g3-Sq for pgsql-hackers@arkaria.postgresql.org; Sat, 10 Jul 2021 17:30:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m2GoQ-0006al-9E for pgsql-hackers@arkaria.postgresql.org; Sat, 10 Jul 2021 17:30:46 +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 1m2GoQ-0006X5-1Q for pgsql-hackers@lists.postgresql.org; Sat, 10 Jul 2021 17:30:46 +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 1m2GoO-00052B-62 for pgsql-hackers@lists.postgresql.org; Sat, 10 Jul 2021 17:30:45 +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 16AHUgBP2407773; Sat, 10 Jul 2021 13:30:42 -0400 From: Tom Lane To: Dean Rasheed cc: pgsql-hackers@lists.postgresql.org Subject: Re: pgsql: Fix numeric_mul() overflow due to too many digits after decimal In-reply-to: References: <2387728.1625929272@sss.pgh.pa.us> Comments: In-reply-to Dean Rasheed message dated "Sat, 10 Jul 2021 18:03:54 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2407771.1625938242.1@sss.pgh.pa.us> Date: Sat, 10 Jul 2021 13:30:42 -0400 Message-ID: <2407772.1625938242@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk [ moving to pghackers for wider visibility ] Dean Rasheed writes: > On Sat, 10 Jul 2021 at 16:01, Tom Lane wrote: >> 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. > Perhaps we should amend the statement about numeric multiplication to > say that it's exact within the limits of the numeric type's supported > scale, which we also document in the manual as 16383. > That seems a lot better than throwing an overflow error for a result > that isn't very big, which limits what's possible with numeric > multiplication to much less than 16383 digits. TBH, I don't agree. I think this is strictly worse than what we did before, and we should just revert it. It's no longer possible to reason about what numeric multiplication will do. I think throwing an error if we can't represent the result exactly is a preferable behavior. If you don't want exact results, use float8. regards, tom lane