Thread: ERROR: function round(double precision, integer) does not exist - WTF?

ERROR: function round(double precision, integer) does not exist - WTF?

From
"Glen Parker"
Date:
 > I think in 7.2 such conversions were allowed silently, but we
> have reduced the number of implicit type coercions.

I'm sensing some brain damage going on here...

DB=# select round(100::int, 2);
 round
--------
 100.00
(1 row)

And...

DB=# create temp table test2(field1 float, field2 decimal);
CREATE TABLE DB=# insert into test2 values(1,1); INSERT
32200009 1 DB=# update test2 set field1=field2 field2=field1; UPDATE 1

So the coercions work fine most of the time.  I still say
it's broken :-)

Glen Parker


Re: ERROR: function round(double precision, integer) does not exist - WTF?

From
"Glen Parker"
Date:
> The guideline we've used for implicit coercions is that in
> the numeric type family, only "up conversions" are implicit, that is
> int2->int4->int8->numeric->float4->float8.  "Down conversions" are
> marked as assignment-only.  Without some such restriction,
> there's nothing to keep the parser from making very
> surprising choices of operators.

I was unaware of the details, yes, but your explanation makes perfect sense.
When I say it's broken though, I'm talking more specifically about trying to
use round(float, int); is there some reason that this function overload
should not exist in the absence of an implicit float->numeric cast?
Rounding a floating-point to a specific number of decimal places is a common
enough operation after all...

Glen Parker


"Glen Parker" <glenebob@nwlink.com> writes:
> When I say it's broken though, I'm talking more specifically about trying to
> use round(float, int); is there some reason that this function overload
> should not exist in the absence of an implicit float->numeric cast?

Send a patch ... I don't recall anyone ever claiming that Postgres has a
complete set of functions ...

            regards, tom lane