Search Postgresql Archives

Re: simple division

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux