Re: round(real,integer)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Paul Ramsey <pramsey(at)cleverelephant(dot)ca>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: round(real,integer)
Date: 2014-01-10 20:37:02
Message-ID: 16232.1389386222@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Paul Ramsey <pramsey(at)cleverelephant(dot)ca> writes:
> History question:
> Why does select round(3,3) work,
> select round(3.0,3) work,
> but select round(3.0::real,1) not work?

The 2-argument round() function actually takes (numeric, integer).

There's an implicit cast from int to numeric, but not an implicit
cast from real to numeric (for that pair of types, the direction
of implicit casting is from numeric to real).

The choices we made for implicit casting behavior among the numeric
datatypes are based on what it says in the SQL standard about exact and
approximate numeric types. There's probably room for argument about
the details, but it seems unlikely that we'd risk the breakage that'd
ensue from rejiggering the casting rules at this stage.

If this annoys you enough, a more realistic solution would be to add
an additional round(float8, int) function. I think it'd have to return
numeric though if you don't want surprises.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Paul Ramsey 2014-01-10 20:52:43 Re: round(real,integer)
Previous Message Preston Hagar 2014-01-10 20:33:46 Re: Question about memory usage