Re: Allow round() function to accept float and double precision - Mailing list pgsql-hackers

From David Rowley
Subject Re: Allow round() function to accept float and double precision
Date
Msg-id CAApHDvrJJineij7Vay0Pc+NAhVYvvMwd-hLoJMZc6ES3t-f=Sg@mail.gmail.com
Whole thread Raw
In response to Re: Allow round() function to accept float and double precision  (Dean Rasheed <dean.a.rasheed@gmail.com>)
Responses Re: Allow round() function to accept float and double precision
List pgsql-hackers
On Thu, 1 Dec 2022 at 21:55, Dean Rasheed <dean.a.rasheed@gmail.com> wrote:
> Casting to numeric(1000, n) will work fine in all cases AFAICS (1000
> being the maximum allowed precision in a numeric typemod, and somewhat
> more memorable).

I wasn't aware of the typemod limit.

I don't really agree that it will work fine in all cases though. If
the numeric has more than 1000 digits left of the decimal point then
the method won't work at all.

# select length(('1' || repeat('0',2000))::numeric(1000,0)::text);
ERROR:  numeric field overflow
DETAIL:  A field with precision 1000, scale 0 must round to an
absolute value less than 10^1000.

No issue with round() with the same number.

# select length(round(('1' || repeat('0',2000))::numeric,0)::text);
 length
--------
   2001

David



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Error-safe user functions
Next
From: Tom Lane
Date:
Subject: Re: Allow round() function to accept float and double precision