Skip site navigation (1) Skip section navigation (2)

Re: BUG #3230: Division problem

From: Jon Sime <jsime(at)mediamatters(dot)org>
To: Jeferson Kasper <jefersonkasper(at)gmail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #3230: Division problem
Date: 2007-04-16 18:18:27
Message-ID: 4623BDF3.7030007@mediamatters.org (view raw or flat)
Thread:
Lists: pgsql-bugs
Jeferson Kasper wrote:
> The following bug has been logged online:
> 
> Bug reference:      3230
> Logged by:          Jeferson Kasper
> Email address:      jefersonkasper(at)gmail(dot)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/

In response to

pgsql-bugs by date

Next:From: CarstenDate: 2007-04-16 23:56:29
Subject: BUG #3232: Regression: pgsql server startup problem with encrypted partitions
Previous:From: Theodore PetroskyDate: 2007-04-16 18:17:30
Subject: Re: BUG #3230: Division problem

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group