Re: simple division

Поиск
Список
Период
Сортировка
От Thomas Kellerer
Тема Re: simple division
Дата
Msg-id 1cbf43df-b495-f5f2-fcfd-b610a279e17b@gmx.net
обсуждение исходный текст
Ответ на Re: simple division  (Martin Mueller <martinmueller@northwestern.edu>)
Список pgsql-general
Martin Mueller schrieb am 04.12.2018 um 21:57:
> I didn't formulate my question properly, because the query went like
>   "select alldefects /wordcount"
> where alldefects and wordcount are integers.   
> But none of the different ways of putting the double colon seemed to
> work.
One way is to make one of the integers a decimal by multiplying with 1.0

    select alldefects * 1.0 / wordcount

> The Postgres notation of this simple procedure is very unintuitive. I
> haven't been able to remember several times, and most people think of
> me as a person with a reasonably good memory.

Postgres supports the SQL standard's CAST operator:

    select cast(alldefects as decimal) / wordcount

The "Postgres way" would be:

    select alldefects::decimal / wordcount

> There is no obvious place in the documentation to look this up.

This is covered in the chapter "Type Casts"

https://www.postgresql.org/docs/current/sql-expressions.html#SQL-SYNTAX-TYPE-CASTS




В списке pgsql-general по дате отправления:

Предыдущее
От: Martin Mueller
Дата:
Сообщение: Re: simple division
Следующее
От: Rob Sargent
Дата:
Сообщение: Re: simple division