From: | Michael Paquier <michael(dot)paquier(at)gmail(dot)com> |
---|---|
To: | Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Pedro Gimeno <pgsql-004(at)personal(dot)formauri(dot)es>, rschaaf(at)commoninf(dot)com, pgsql-bugs(at)postgresql(dot)org |
Subject: | Re: Re: BUG #12885: The result of casting a double to an integer depends on the database version |
Date: | 2015-03-27 12:32:38 |
Message-ID: | CAB7nPqRq94VT5WiYyCjSS+E_=mwWL49W-MXv5qgyR-8S91YY-w@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
On Thu, Mar 26, 2015 at 11:15 AM, Michael Paquier
<michael(dot)paquier(at)gmail(dot)com> wrote:
> On Thu, Mar 26, 2015 at 11:12 AM, Andrew Gierth wrote:
>>>>>>> "Michael" == Michael Paquier writes:
>>
>> Michael> Indeed...
>> Michael> =# select column1 AS double_value, cast(column1 AS INT) AS
>> Michael> int_value
>>
>> The complication for numeric is that there's also the case of round(x,n)
>> and casting to numeric(m,n) to consider.
>
> OK, thanks for the reminder... I forgot this case.
Attached is a patch that adds nearest-to-even rounding for numeric
when dscale = 0. This gives the following results with the previous
query:
=# select column1 AS double_value, cast(column1 AS INT) AS int_value
FROM (VALUES
(-2.5::numeric),
(-1.5::numeric),
(-0.5::numeric),
(0.5::numeric),
(1.5::numeric),
2.5::numeric)) t;
double_value | int_value
--------------+-----------
-2.5 | -2
-1.5 | -2
-0.5 | 0
0.5 | 0
1.5 | 2
2.5 | 2
(6 rows)
For the case where dscale != 0 case, what would we actually want? I
have been staring at the code around round_var for some time but I
could not really get if we'd really want to change something there...
For example round(2.5::numeric, 1) should be 2.4 and not 2.5?
Regards.
--
Michael
Attachment | Content-Type | Size |
---|---|---|
20150327_numeric_infinite_loop.patch | application/x-patch | 881 bytes |
From | Date | Subject | |
---|---|---|---|
Next Message | Dean Rasheed | 2015-03-27 17:16:01 | Re: Re: BUG #12885: The result of casting a double to an integer depends on the database version |
Previous Message | pet.slavov | 2015-03-27 09:47:57 | BUG #12910: Memory leak with logical decoding |