Re: Simple sql question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Tore Lukashaugen" <tore(at)lukashaugen(dot)freeserve(dot)co(dot)uk>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Simple sql question
Date: 2007-10-03 18:44:39
Message-ID: 29692.1191437079@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

"Tore Lukashaugen" <tore(at)lukashaugen(dot)freeserve(dot)co(dot)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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Tore Lukashaugen 2007-10-03 18:56:57 Re: Simple sql question
Previous Message Brian Hurt 2007-10-03 18:43:43 Re: Simple sql question