Re: Simple sql question - Mailing list pgsql-novice

From Tom Lane
Subject Re: Simple sql question
Date
Msg-id 29692.1191437079@sss.pgh.pa.us
Whole thread Raw
In response to Simple sql question  ("Tore Lukashaugen" <tore@lukashaugen.freeserve.co.uk>)
List 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 by date:

Previous
From: Brian Hurt
Date:
Subject: Re: Simple sql question
Next
From: "Tore Lukashaugen"
Date:
Subject: Re: Simple sql question