Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-novice by date

Next:From: Tore LukashaugenDate: 2007-10-03 18:56:57
Subject: Re: Simple sql question
Previous:From: Brian HurtDate: 2007-10-03 18:43:43
Subject: Re: Simple sql question

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group