Re: BUG #12885: The result of casting a double to an integer depends on the database version

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: rschaaf(at)commoninf(dot)com, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #12885: The result of casting a double to an integer depends on the database version
Date: 2015-03-24 02:27:31
Message-ID: CAB7nPqQjby+5wAc-gcD77HZRA44CJpbxrD9t83s8C7cT7D5o9g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, Mar 23, 2015 at 7:48 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> rschaaf(at)commoninf(dot)com writes:
>> The result returned by the following query appears to depend on the
>> PostgreSQL database version.
>
>> The query is:
>> select column1 AS double_value, cast(column1 AS INT) AS int_value
>> from (VALUES (-2.5::double precision),
>> (-1.5::double precision),
>> (-0.5::double precision),
>> (0.5::double precision),
>> (1.5::double precision),
>> (2.5::double precision)) t;
>
>> In PostgreSQL 9.3.5, the query returns:
>> double_value, int_value
>> -2.5, -3
>> -1.5, -2
>> -0.5, -1
>> 0.5, 1
>> 1.5, 2
>> 2.5, 3
>
>> PostgreSQL 9.4.1, the query returns:
>> -2.5, -2
>> -1.5, -2
>> -0.5, 0
>> 0.5, 0
>> 1.5, 2
>> 2.5, 2
>
> FWIW, I get the latter behavior (round to nearest even) in all release
> branches, and I would say that one is correct. Not real sure why your
> 9.3 installation is misbehaving.

On a Windows 7 box with code compiled with MSVC 2010 I am seeing the
same behavior as Rich. This looks like a bug in ~9.3 that meritates
some attention assuming that the latter behavior is legit.
--
Michael

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2015-03-24 02:42:16 Re: BUG #12885: The result of casting a double to an integer depends on the database version
Previous Message Michael Paquier 2015-03-23 23:34:57 Re: BUG #12889: Documentation