Обсуждение: BUG #5605: round(attr_name,int) works bad

Поиск
Список
Период
Сортировка

BUG #5605: round(attr_name,int) works bad

От
"Adam Radlowski"
Дата:
The following bug has been logged online:

Bug reference:      5605
Logged by:          Adam Radlowski
Email address:      adamr@informatyka.gdansk.pl
PostgreSQL version: 8.4.4
Operating system:   Gentoo 64 bit (PSQL 8.4.4), Fedora 12 32 bit (PSQL
8.4.1)
Description:        round(attr_name,int) works bad
Details:

On both systems simmilar problems:
PSQL 8.4.4 (taken from "www.postgresql.org" and compiled on 64 bit latest
Gentoo)
PSQL 8.4.1 (from Fedora 12 distribution disk):

If I try for example:
select round(any_numeric_field*something,2) from any_table;
I get information, that the function dos not exist.
If I use round(numeric_field*something,int) in "insert" command, round
returns always only the value of "numeric_field".


Comment:
In some cases I can use for example:
select round(100.0*any_numeric_field)/100.0 from any_table;
..but in programs wchich are generating SQL code and I can't modify them it
is important problem.

Re: BUG #5605: round(attr_name,int) works bad

От
Alex Hunsaker
Дата:
On Fri, Aug 6, 2010 at 02:12, Adam Radlowski
<adamr@informatyka.gdansk.pl> wrote:
> PostgreSQL version: 8.4.4
> Operating system: =C2=A0 Gentoo 64 bit (PSQL 8.4.4), Fedora 12 32 bit (PS=
QL
> 8.4.1)

> select round(any_numeric_field*something,2) from any_table;
> I get information, that the function dos not exist.

Can we get the exact *input* and the error?  I cant replicate it here:
select round(100::numeric*100, 2);

> If I use round(numeric_field*something,int) in "insert" command, round
> returns always only the value of "numeric_field".

So... insert into table (field) values (round(100*2, 1)) inserts 100?
I find that quite hard to believe.  Again some actually sql might help
here as I might just be misunderstanding.

> Comment:
> In some cases I can use for example:
> select round(100.0*any_numeric_field)/100.0 from any_table;
> ..but in programs wchich are generating SQL code and I can't modify them =
it
> is important problem.

Sounds like a problem with whatever is generating the SQL not a
problem with postgres.

Re: BUG #5605: round(attr_name,int) works bad

От
Tom Lane
Дата:
Alex Hunsaker <badalex@gmail.com> writes:
> On Fri, Aug 6, 2010 at 02:12, Adam Radlowski
>> select round(any_numeric_field*something,2) from any_table;
>> I get information, that the function dos not exist.

> Can we get the exact *input* and the error?  I cant replicate it here:
> select round(100::numeric*100, 2);

I'm betting that by "any_numeric_field", the OP actually means a float
field, or perhaps his "something" was float. There's no float variant of
two-parameter round():

regression=# \df round
                          List of functions
   Schema   | Name  | Result data type | Argument data types |  Type
------------+-------+------------------+---------------------+--------
 pg_catalog | round | double precision | double precision    | normal
 pg_catalog | round | numeric          | numeric             | normal
 pg_catalog | round | numeric          | numeric, integer    | normal
(3 rows)

Fix would be to cast the function's first parameter to numeric.
Or if you can't fool with the generated SQL, make your own
round(float8, int) that does that.

            regards, tom lane