Re: pgsql: Fix numeric_mul() overflow due to too many digits after decimal

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: pgsql: Fix numeric_mul() overflow due to too many digits after decimal
Date: 2021-07-10 17:30:42
Message-ID: 2407772.1625938242@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

[ moving to pghackers for wider visibility ]

Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> writes:
> On Sat, 10 Jul 2021 at 16:01, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> 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

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Jeff Davis 2021-07-10 17:44:03 pgsql: Fix assign_record_type_typmod().
Previous Message Tom Lane 2021-07-10 17:19:48 pgsql: Fix busted test for ldap_initialize.

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Davis 2021-07-10 17:58:29 Re: [EXTERNAL] Re: Crash in record_type_typmod_compare
Previous Message Fabien COELHO 2021-07-10 17:19:45 Re: [HACKERS] WIP aPatch: Pgbench Serialization and deadlock errors