Re: Aggregate Functions

From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: Yadnyesh Joshi <yadnyesh_joshi(at)yahoo(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Aggregate Functions
Date: 2006-11-20 05:43:35
Message-ID: 139316.44087.qm@web31809.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

> According to the documentation, when "avg" or "stddev" function is used with integer arguments,
> the result is an integer. How can I obtain floating point result (for more accuracy) while using
> "avg" or "stddev" function on integer arguments?
> Thank you,
> Yadnyesh.

It looks to me that is already does:

mydb=> \d+ test;
Table "public.test"
Column | Type | Modifiers | Description
---------+-----------------------------+-----------+-------------
id_i | integer | not null |
ir_id | integer | not null |
test | boolean | |
stamp | timestamp without time zone | |
inttest | integer | |
Indexes:
"test_pk" PRIMARY KEY, btree (id_i, ir_id)
Has OIDs: no

mydb=> select * from test limit 5;
id_i | ir_id | test | stamp | inttest
------+-------+------+---------------------+---------
1 | 9 | f | 2006-06-19 04:30:00 | 0
1 | 10 | f | 2006-06-19 05:30:00 | 0
1 | 3 | t | 2006-06-05 03:00:00 | 1
2 | 4 | t | 2006-06-05 04:00:00 | 1
3 | 6 | t | 2006-06-05 06:00:00 | 1
(5 rows)

mydb=> select avg(id_i) from test;
avg
---------------------
37.5679012345679012
(1 row)

mydb=> select stddev(id_i) from test;
stddev
---------------------
23.3285974029756760
(1 row)

Regards,

Richard Broersma Jr.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message A. Kretschmer 2006-11-20 06:06:53 Re: Aggregate Functions
Previous Message Tom Lane 2006-11-20 05:23:27 Re: Aggregate Functions