Re: Allow round() function to accept float and double precision
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Dean Rasheed <dean.a.rasheed@gmail.com>
Cc: David Rowley <dgrowleyml@gmail.com>,
"David G. Johnston" <david.g.johnston@gmail.com>,
Sayyid Ali Sajjad Rizavi <sasrizavi@gmail.com>,
pgsql-hackers@lists.postgresql.org
Date: 2022-12-01T14:39:53Z
Lists: pgsql-hackers
Dean Rasheed <dean.a.rasheed@gmail.com> writes: > I don't really see the point of such a function either. > 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). Right, but I think what the OP wants is to not have to think about whether the input is of exact or inexact type. That's easily soluble locally by making your own function: create function round(float8, int) returns numeric as $$select pg_catalog.round($1::pg_catalog.numeric, $2)$$ language sql strict immutable parallel safe; but I'm not sure that the argument for it is strong enough to justify putting it into Postgres. > The fact that passing a negative scale to round() isn't documented > does seem like an oversight though... Agreed, will do something about that. regards, tom lane
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