Re: simple division

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: simple division
Date: 2018-12-04 20:41:51
Message-ID: 29902835-a789-9b23-b236-f74a929b3bc3@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 DB2 behave 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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2018-12-04 20:42:29 Re: simple division
Previous Message Igor Neyman 2018-12-04 20:38:15 RE: simple division