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

Re: Simple sql question

From: "Tore Lukashaugen" <tore(at)lukashaugen(dot)freeserve(dot)co(dot)uk>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Simple sql question
Date: 2007-10-03 18:56:57
Message-ID: 7E99B849756344CC8DE982886CBC681E@ToreServer (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
Indeed it does, thanks very much guys!

----- Original Message ----- 
From: "Wright, George" <George(dot)Wright(at)infimatic(dot)com>
To: "Tore Lukashaugen" <tore(at)lukashaugen(dot)freeserve(dot)co(dot)uk>; 
Sent: Wednesday, October 03, 2007 7:35 PM
Subject: Re: [NOVICE] Simple sql question

select cast (col1 as float) / cast (col2 as float) from test;

gives 0.5

-----Original Message-----
From: pgsql-novice-owner(at)postgresql(dot)org
[mailto:pgsql-novice-owner(at)postgresql(dot)org] On Behalf Of Tore Lukashaugen
Sent: Wednesday, October 03, 2007 2:02 PM
To: pgsql-novice(at)postgresql(dot)org
Subject: [NOVICE] Simple sql question


I am new to Postgres and have an embarassingly simple question. I am
v8.2 on Windows Vista although I don't think that has any bearing on the


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
to be casted somehow? Or is it because PGAdmin's SQL interface does not
default show the decimal places of output?

Appreciate your help.


---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
       message can get through to the mailing list cleanly

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at


In response to


pgsql-novice by date

Next:From: Lonni J FriedmanDate: 2007-10-05 22:47:45
Subject: timestamp interval issue
Previous:From: Tom LaneDate: 2007-10-03 18:44:39
Subject: Re: Simple sql question

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