Re: simple division

Поиск
Список
Период
Сортировка
От Thomas Kellerer
Тема Re: simple division
Дата
Msg-id 29902835-a789-9b23-b236-f74a929b3bc3@gmx.net
обсуждение исходный текст
Ответ на simple division  (Martin Mueller <martinmueller@northwestern.edu>)
Список 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 по дате отправления:

Предыдущее
От: Igor Neyman
Дата:
Сообщение: RE: simple division
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: simple division