BUG #3230: Division problem

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

BUG #3230: Division problem

От:
"Jeferson Kasper" <jefersonkasper@gmail.com>
Дата:
The following bug has been logged online:

Bug reference:      3230
Logged by:          Jeferson Kasper
Email address:      jefersonkasper@gmail.com
PostgreSQL version: 8.1.5
Operating system:   Linux RedHat 9
Description:        Division problem
Details: 

i was trying to divide a number and the result is always wrong, and i tried
to calculate in psql this query:

select (30/50);

and the result was zero ( 0 ), and it have to be 0.6...
i dont know what i have done wrong... but, i think its a bug.
thanks for all.

Jeferson Kasper

Re: BUG #3230: Division problem

От:
Theodore Petrosky <tedpet5@yahoo.com>
Дата:
try:

select 30/50::float;


?column? 
----------
      0.6
(1 row)


Ted

--- Jeferson Kasper  wrote:

> 
> The following bug has been logged online:
> 
> Bug reference:      3230
> Logged by:          Jeferson Kasper
> Email address:      jefersonkasper@gmail.com
> PostgreSQL version: 8.1.5
> Operating system:   Linux RedHat 9
> Description:        Division problem
> Details: 
> 
> i was trying to divide a number and the result is
> always wrong, and i tried
> to calculate in psql this query:
> 
> select (30/50);
> 
> and the result was zero ( 0 ), and it have to be
> 0.6...
> i dont know what i have done wrong... but, i think
> its a bug.
> thanks for all.
> 
> Jeferson Kasper
> 
> ---------------------------(end of
> broadcast)---------------------------
> TIP 6: explain analyze is your friend
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com

Re: BUG #3230: Division problem

От:
Jon Sime <jsime@mediamatters.org>
Дата:
Jeferson Kasper wrote:
> The following bug has been logged online:
> 
> Bug reference:      3230
> Logged by:          Jeferson Kasper
> Email address:      jefersonkasper@gmail.com
> PostgreSQL version: 8.1.5
> Operating system:   Linux RedHat 9
> Description:        Division problem
> Details: 
> 
> i was trying to divide a number and the result is always wrong, and i tried
> to calculate in psql this query:
> 
> select (30/50);
> 
> and the result was zero ( 0 ), and it have to be 0.6...
> i dont know what i have done wrong... but, i think its a bug.
> thanks for all.
> 
> Jeferson Kasper

Operations on integer arguments will return an integer result. To get
the value you're expecting from that division, you'll need to cast one
of the numbers to a floating point type.

Any of the following will produce the result you wanted:

    select cast(30 as real) / 50;
    select cast(30 as numeric) / 50;
    select 30::real / 50;
    select 30 / 50::float;

As well as any other variations along that theme.

-Jon

--
Senior Systems Developer
Media Matters for America
http://mediamatters.org/
FAQ