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

Started by Glen Parkerabout 22 years ago3 messagesgeneral
Jump to latest
#1Glen Parker
glenebob@nwlink.com

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

#2Glen Parker
glenebob@nwlink.com
In reply to: Glen Parker (#1)
Re: ERROR: function round(double precision, integer) does not exist - WTF?

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

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Glen Parker (#2)
Re: ERROR: function round(double precision, integer) does not exist - WTF?

"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