Re: avg(interval)

From: Joe <dev(at)freedomcircle(dot)net>
To: Erik Jones <erik(at)myemma(dot)com>
Cc: Aaron Bono <postgresql(at)aranya(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jeremiah Elliott <geek00(at)gmail(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: avg(interval)
Date: 2006-06-27 03:20:26
Message-ID: 44A0A3FA.4010404@freedomcircle.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Erik Jones wrote:
> Well, the query is working ok numerically, but should the answer really
> be reported as 4 days and 33 hours?

Well, the original poster didn't provide the table schema or PG version,
but on PG 8.0.3 both with intervals or with differences between
timestamps, the query appears to work OK:

test=> select * from x;
t
-----------------
7 days 22:24:00
9 days 22:21:00
23:21:00
4 days 22:47:00
3 days 06:05:00
(5 rows)

test=> select avg(t) from x;
avg
-----------------
5 days 09:47:36
(1 row)

test=> select * from x2;
t
---------------------
2006-06-07 22:24:00
2006-06-09 22:21:00
2006-05-31 23:21:00
2006-06-04 22:47:00
2006-06-03 06:05:00
(5 rows)

test=> select avg(t - '2006-5-31 0:0'::timestamp) from x2;
avg
-----------------
5 days 09:47:36
(1 row)

Joe

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Forums @ Existanze 2006-06-27 08:16:17 Re: Fwd: Start up question about triggers
Previous Message Erik Jones 2006-06-27 02:49:26 Re: avg(interval)