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

From: Pedro Gimeno <pgsql-004(at)personal(dot)formauri(dot)es>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>, 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 17:53:11
Message-ID: 55159907.1060809@personal.formauri.es
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Michael Paquier wrote, On 2015-03-27 13:32:

> Attached is a patch that adds nearest-to-even rounding for numeric
> when dscale = 0. This gives the following results with the previous
> query:

That produces some quite surprising results:

=# select '2.5'::numeric(9,0)::numeric(9,1),
'2.25'::numeric(9,1)::numeric(9,2),
'2.225'::numeric(9,2)::numeric(9,3),
'2.2225'::numeric(9,3)::numeric(9,4),
'2.22225'::numeric(9,4)::numeric(9,5);
numeric | numeric | numeric | numeric | numeric
---------+---------+---------+---------+---------
2.0 | 2.30 | 2.230 | 2.2230 | 2.22220
(1 row)

That rounding is inconsistent: since DEC_DIGITS is 4 by default, numbers
with a number of digits which is a multiple of 4 + 1 will be rounded to
nearest or even, and numbers with a different number of digits will be
rounded up on a tie. And I have not tested, but apparently when
DEC_DIGITS == 1 (array elements are single digits rather than packing
several) it always rounds down on a tie.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Alejandro Guimaraens 2015-03-27 19:34:38 problem with pgAdminIII from Spain
Previous 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