Re: Aggregate Functions - Mailing list pgsql-novice

From Richard Broersma Jr
Subject Re: Aggregate Functions
Date
Msg-id 139316.44087.qm@web31809.mail.mud.yahoo.com
Whole thread Raw
In response to Aggregate Functions  (Yadnyesh Joshi <yadnyesh_joshi@yahoo.com>)
List 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.

pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: Aggregate Functions
Next
From: "A. Kretschmer"
Date:
Subject: Re: Aggregate Functions