Re: dividing integers not producing decimal fractions

From: Alexander Staubo <alex(at)purefiction(dot)net>
To: rloefgren(at)forethought(dot)net
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: dividing integers not producing decimal fractions
Date: 2006-11-03 17:06:41
Message-ID: 780EC036-E650-463F-9F8B-58CA31EEC9EA@purefiction.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Nov 2, 2006, at 23:54 , rloefgren(at)forethought(dot)net wrote:

> I'm trying to produce a decimal fraction by dividing integer fields
> like this fragment of the query:
>
> ...((cntoh0.count + cntoh1.count)/ttl_deptcat.ttlcount) as "Ratio"...
...
> How do I get fractions when dividing integers? Cast as something?

Exactly. Just as in most computer languages, incidentally:

# select 1 / 2 as x;
x
---
0
(1 row)

# select 1 / 2::float as x;
x
-----
0.5
(1 row)

Alexander.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andreas Kretschmer 2006-11-03 17:07:49 Re: creating a dumpfile from a view
Previous Message Joshua D. Drake 2006-11-03 17:06:32 Re: Can PostgreSQL reside on the same server as MSDE?