Re: simple division - Mailing list pgsql-general

From David G. Johnston
Subject Re: simple division
Date
Msg-id CAKFQuwYp1CJ_Aux0jSUQ_TsJ0zsPxQOEkWZp3kSyDmQZ0ZVNJA@mail.gmail.com
Whole thread Raw
In response to simple division  (Martin Mueller <martinmueller@northwestern.edu>)
List 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 by date:

Previous
From: Thomas Kellerer
Date:
Subject: Re: simple division
Next
From: "David G. Johnston"
Date:
Subject: Re: simple division