Re: Re: BUG #12885: The result of casting a double to an integer depends on the database version
От | Michael Paquier |
---|---|
Тема | Re: Re: BUG #12885: The result of casting a double to an integer depends on the database version |
Дата | |
Msg-id | CAB7nPqRq94VT5WiYyCjSS+E_=mwWL49W-MXv5qgyR-8S91YY-w@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Re: BUG #12885: The result of casting a double to an integer depends on the database version (Michael Paquier <michael.paquier@gmail.com>) |
Ответы |
Re: Re: BUG #12885: The result of casting a double to an
integer depends on the database version
Re: Re: BUG #12885: The result of casting a double to an integer depends on the database version |
Список | pgsql-bugs |
On Thu, Mar 26, 2015 at 11:15 AM, Michael Paquier <michael.paquier@gmail.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
Вложения
В списке pgsql-bugs по дате отправления: