Re: Inconsistent results postgresql - Mailing list pgsql-general

From Kevin Grittner
Subject Re: Inconsistent results postgresql
Date
Msg-id 1406812438.91316.YahooMailNeo@web122305.mail.ne1.yahoo.com
Whole thread Raw
In response to Re: Inconsistent results postgresql  (Chris Curvey <chris@chriscurvey.com>)
List pgsql-general
Chris Curvey <chris@chriscurvey.com> wrote:
> Emir Ibrahimbegovic <emir.ibrahimbegovic@gmail.com> wrote:

>> So looking for same date using different date range I get
>> different results, how is this even possible? Can I look at
>> something else? I'm really stuck here

> Remove the sum (just select "payments.amount") and the GROUP BY
> and run your queries.  You'll see that you're getting different
> rows included than you think you are.

Well, either that or he's getting them in a different order and the
data type being summed is a floating point approximate type.  With
the approximate types the order that addition happens in can affect
the sum.  For the most accurate result you want to add from the
numbers closest to zero to the ones farthest away from zero.

If exact results are desired, the best solution is to not use an
approximate data type.  Try converting the column to numeric, which
is not as vulnerable to rounding errors.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


pgsql-general by date:

Previous
From: Emir Ibrahimbegovic
Date:
Subject: Re: Inconsistent results postgresql
Next
From: Merlin Moncure
Date:
Subject: Re: String concatenation operator which keeps trailing spaces in CHAR(n) columns