X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id A225B9FA6B3 for ; Mon, 26 Jun 2006 18:22:28 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 24804-04 for ; Mon, 26 Jun 2006 18:22:16 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.239]) by postgresql.org (Postfix) with ESMTP id 527169FA10A for ; Mon, 26 Jun 2006 18:22:11 -0300 (ADT) Received: by wr-out-0506.google.com with SMTP id i7so120023wra for ; Mon, 26 Jun 2006 14:22:11 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=Siog9drswWwO1C117/OGCxWGesm27VUSldXfHsmhPKf2VEqs86ZQozUw2ClbuNHLUTyoe+WJ7eX77ClIkNu7ZP6q0scLY4B49mv6gU+lAmIEFD1NcB10ZN8VaKS4mNVAKOf1/EmJ5wVy8yRcF8DOG5Jl0kjhi+WiMx76NjmD3ho= Received: by 10.54.134.12 with SMTP id h12mr7672044wrd; Mon, 26 Jun 2006 14:22:11 -0700 (PDT) Received: by 10.54.111.9 with HTTP; Mon, 26 Jun 2006 14:22:11 -0700 (PDT) Message-ID: <17eca7f50606261422m77395b89ufb713720defb8b42@mail.gmail.com> Date: Mon, 26 Jun 2006 16:22:11 -0500 From: "Jeremiah Elliott" To: pgsql-sql@postgresql.org Subject: avg(interval) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/270 X-Sequence-Number: 25506 I am getting some really strange query output. I am trying to average an interval. The problem is that the interval average is sometimes returning more than 24 hours for the average. query: select avg(scan_date - backflush_date) as time_diff, substring(pt_article, 1, 5) as clan, sum(qty) as units from carton_master join outbound on master_number = master_id join pt_mstr on product = pt_part where scan_date::date between '2006-06-01'::date and '2006-07-01'::date and substring(pt_article, 1, 5) = '*2420' group by clan output: 4 days 33:48:13.994333 *2420 25 however if i don't average them here is what i get: query: select (scan_date - backflush_date) as time_diff, substring(pt_article, 1, 5) as clan from carton_master join outbound on master_number = master_id join pt_mstr on product = pt_part where scan_date::date between '2006-06-01'::date and '2006-07-01'::date and substring(pt_article, 1, 5) = '*2420' output: "7 days 22:24:50.62311";"*2420" "9 days 22:21:02.683393";"*2420" "23:21:35.458459";"*2420" "4 days 22:47:41.749756";"*2420" "3 days 06:05:59.456947";"*2420" which should average to just over nine days - Assuming I am not missing something huge here. I tend to think its a bug in avg(interval) postgres function. I am running postgres 8.1.3 on 32bit suse Thanks Jeremiah Elliott