On Tue, Dec 4, 2018 at 1:29 PM Martin Mueller <martinmuel...@northwestern.edu> wrote: > I have asked this question before and apologize for not remembering it. How > do you do simple division in postgres and get 10/4 with decimals? > This involves cast and numeric in odd ways that are not well explained in the > documentation. For instance, you’d expect an 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.