Re: Simple sql question

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Simple sql question
Дата
Msg-id 29692.1191437079@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Simple sql question  ("Tore Lukashaugen" <tore@lukashaugen.freeserve.co.uk>)
Список pgsql-novice
"Tore Lukashaugen" <tore@lukashaugen.freeserve.co.uk> writes:
> create table test (col1 int, col2 int)
> insert into test values (1,2);
> select col1/col2 from test....yields 0 not 0.5 - why?

> Presumably this is because both col1 and col2 are ints and the output needs
> to be casted somehow?

Yup --- division of integers yields an integer result.

If you want a fractional result, cast one or both inputs of the division
to numeric or float.

            regards, tom lane

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

Предыдущее
От: Brian Hurt
Дата:
Сообщение: Re: Simple sql question
Следующее
От: "Tore Lukashaugen"
Дата:
Сообщение: Re: Simple sql question