Re: simple division - Mailing list pgsql-general

From Thomas Kellerer
Subject Re: simple division
Date
Msg-id 29902835-a789-9b23-b236-f74a929b3bc3@gmx.net
Whole thread Raw
In response to simple division  (Martin Mueller <martinmueller@northwestern.edu>)
List pgsql-general
Martin Mueller schrieb am 04.12.2018 um 21:29:
> 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?

In the expression 10/4 both numbers are integers.
And an integer divsion does not yield decimals (that's the same as in every strongly typed programming language).

I am not entirely sure what the SQL standard says about such an expression, but e.g. SQL Server, SQLite, Firebird and
DB2behave the same as Postgres.
 
That is they apply integer division if all values are integers, and decimal division if at least one value is a
decimal.

To get a division of decimals you need to specify at least one value as a decimal,

e.g. "select 10.0/4" or "select 10/4.0" whatever you prefer.


pgsql-general by date:

Previous
From: Igor Neyman
Date:
Subject: RE: simple division
Next
From: "David G. Johnston"
Date:
Subject: Re: simple division