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

From Tom Lane
Subject Re: Allow round() function to accept float and double precision
Date
Msg-id 1565775.1669905593@sss.pgh.pa.us
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  ("David G. Johnston" <david.g.johnston@gmail.com>)
List 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



pgsql-hackers by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: [DOCS] Stats views and functions not in order?
Next
From: gkokolatos@pm.me
Date:
Subject: Re: Add LZ4 compression in pg_dump