explicitly casting return value of avg() to float4

From: Jon Lapham <lapham(at)extracta(dot)com(dot)br>
To: pgsql-general(at)postgresql(dot)org
Subject: explicitly casting return value of avg() to float4
Date: 2002-04-25 17:50:32
Message-ID: 3CC841E8.40305@extracta.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Is the preferred way to return the average of ::float4 values to
explicitly cast the returned value of avg() to ::float4?

If so, how do people deal with this in end user apps? Do you check to
see whether the column is ::float8 or ::float4 and then use a different
SQL statement? Ugh, I hope not.

main_v0_8=# select version();
version
-------------------------------------------------------------
PostgreSQL 7.2.1 on i686-pc-linux-gnu, compiled by GCC 2.96
(1 row)

main_v0_8=# select avg(0.01::float4);
avg
---------------------
0.00999999977648258
(1 row)

main_v0_8=# select avg(0.01::float4)::float4;
avg
------
0.01
(1 row)

--

-**-*-*---*-*---*-*---*-----*-*-----*---*-*---*-----*-----*-*-----*---
Jon Lapham
Extracta Moléculas Naturais, Rio de Janeiro, Brasil
email: lapham(at)extracta(dot)com(dot)br web: http://www.extracta.com.br/
***-*--*----*-------*------------*--------------------*---------------

Responses

Browse pgsql-general by date

  From Date Subject
Next Message tony 2002-04-25 18:42:04 Re: Look for a French user to help here : Technique doc
Previous Message Justin Clift 2002-04-25 17:26:59 Look for a French user to help here : Technique doc of PostgreSQL