Re: Allow round() function to accept float and double precision
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: Dean Rasheed <dean.a.rasheed@gmail.com>
Cc: "David G. Johnston" <david.g.johnston@gmail.com>,
Tom Lane <tgl@sss.pgh.pa.us>, Sayyid Ali Sajjad Rizavi <sasrizavi@gmail.com>,
pgsql-hackers@lists.postgresql.org
Date: 2022-12-01T19:57:17Z
Lists: 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
Commits
-
Doc: add example of round(v, s) with negative s.
- e10799aa252c 15.2 landed
- a475157e6bf0 13.10 landed
- a109a0bb50ad 16.0 landed
- 7ec2bfe9e031 14.7 landed