Question about the TODO, numerics, and division

Поиск
Список
Период
Сортировка
От Chris Travers
Тема Question about the TODO, numerics, and division
Дата
Msg-id 46005C1F.5040607@metatrontech.com
обсуждение исходный текст
Ответы Re: Question about the TODO, numerics, and division  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Hi all;

I have been looking at the TODO and have found something that I find
sort of odd and we should probably reconsider:

One of the items under data types is:

    * Add NUMERIC division operator that doesn't round?

      Currently NUMERIC _rounds_ the result to the specified precision.
      This means division can return a result that multiplied by the
      divisor is greater than the dividend, e.g. this returns a value > 10:

SELECT (10::numeric(2,0) / 6::numeric(2,0))::numeric(2,0) * 6;

This does not seem to me to be an division op issue but rather a simple
casting mistake.  Note that the result of 10/6 is cast as numeric(2,0)
and then multiplied by 6.

The following example shows that the problem is with the query and
casting, not with the division op:
SELECT ((10::numeric(2,0) / 6::numeric(2,0)) * 6)::numeric(2,0);
 numeric
---------
      10
(1 row)


Am I missing something?

Best Wishes,
Chris Travers



Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: "Florian G. Pflug"
Дата:
Сообщение: Re: modifying the tbale function
Следующее
От: Gavin Sherry
Дата:
Сообщение: Re: Bitmapscan changes - Requesting further feedback