Question about the TODO, numerics, and division
Вложения
В списке pgsql-hackers по дате отправления:
| От | Chris Travers |
|---|---|
| Тема | Question about the TODO, numerics, and division |
| Дата | |
| Msg-id | 46005C1F.5040607@metatrontech.com обсуждение исходный текст |
| Ответы |
Re: Question about the TODO, numerics, and division
|
| Список | 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 по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера