Re: integer instead of 'double precision'?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Henry Drexler <alonup8tb(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: integer instead of 'double precision'?
Date: 2011-09-09 15:12:41
Message-ID: 11955.1315581161@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Henry Drexler <alonup8tb(at)gmail(dot)com> writes:
> [ "1/3" yields zero ]

Yeah, it's an integer division.

> I thought perhaps I could cast it as double precision as noted on
> http://www.postgresql.org/docs/8.3/interactive/sql-expressions.html
> though doing the following:
> float8(1/3)

That's casting the result of the division to float, which is way too
late. You need to cast one or both inputs to non-integer, for instance

1.0/3
1/(3::float8)

etc etc.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Carlos Mennens 2011-09-09 15:35:56 PostgreSQL Upgrade Procedure
Previous Message Guillaume Lelarge 2011-09-09 15:09:58 Re: integer instead of 'double precision'?