Re: simple division

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: simple division
Дата
Msg-id CAKFQuwYp1CJ_Aux0jSUQ_TsJ0zsPxQOEkWZp3kSyDmQZ0ZVNJA@mail.gmail.com
обсуждение исходный текст
Ответ на simple division  (Martin Mueller <martinmueller@northwestern.edu>)
Список pgsql-general
On Tue, Dec 4, 2018 at 1:29 PM Martin Mueller
<martinmueller@northwestern.edu> wrote:
> I have asked this question before and apologize for not remembering it.  How do you do simple division in postgres
andget 10/4 with decimals? 
> This involves cast and numeric in odd ways that are not well explained in the documentation. For instance, you’d
expectan example in the Mathematical Functions. But there isn’t. 

select 10/4, 10.0/4, 10/4.0, 10.0/4.0;

The first one returns 2, the rest of them 2.5 - from which one can
infer that if both inputs are integer (type) the output is integer
(type) - if at least one input is non-integer (type) the output will
be as well.

If you want to cast...select 10/(4::numeric)...

David J.


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

Предыдущее
От: Thomas Kellerer
Дата:
Сообщение: Re: simple division
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: simple division