Received: from actarg.com (host25.actarg.com [209.180.91.25] (may be forged)) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f290L8x46333 for ; Thu, 8 Mar 2001 19:21:08 -0500 (EST) (envelope-from kyle@actarg.com) Received: from chi.actarg.com (IDENT:root@chi.actarg.com [192.168.2.16]) by actarg.com (8.9.3/8.9.3) with ESMTP id RAA22109; Thu, 8 Mar 2001 17:21:04 -0700 Received: from actarg.com (IDENT:kyle@localhost [127.0.0.1]) by chi.actarg.com (8.9.3/8.9.3) with ESMTP id RAA25929; Thu, 8 Mar 2001 17:21:22 -0700 Message-ID: <3AA82201.C22A5BAB@actarg.com> Date: Thu, 08 Mar 2001 17:21:22 -0700 From: Kyle Organization: Action Target Inc. X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.12-20 i686) X-Accept-Language: en MIME-Version: 1.0 To: Tom Lane CC: pgsql-sql@postgresql.org Subject: Re: A query that doesn't work on 7.1 References: <3AA6C0AD.BC8A015A@actarg.com> <19632.984010093@sss.pgh.pa.us> <24466.984016499@sss.pgh.pa.us> <3AA7E16D.C9B4FA76@actarg.com> <29675.984081236@sss.pgh.pa.us> Content-Type: multipart/mixed; boundary="------------29FE3A9ED2E949B086304C63" X-Archive-Number: 200103/185 X-Sequence-Number: 1838 This is a multi-part message in MIME format. --------------29FE3A9ED2E949B086304C63 Content-Type: multipart/alternative; boundary="------------0A04642A3C58B2AC79884C54" --------------0A04642A3C58B2AC79884C54 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Tom Lane wrote: > > Here's another twist though. Is this a bug too or is this just beyond our reach? > > > psql:lead1.sql:64: ERROR: Unable to select an aggregate function avg(date) > > It's just that we don't have any avg() function for date --- nor for > timestamp, which is a little more surprising. > FYI: I got by with kind of a pseudo average (mean, I guess) for now implemented as: min(date) + (max(date) - min(date)/2) > > You could probably gin up a usable avg(timestamp) using the avg(float8) > routines, since a timestamp is really just a double under the hood. > When you say "gin up" are you talking about C, PL/XXX, or just casts? BTW, here's another question: Here's a view of a union. The two selects are fast when executed individually (and explain confirms that they use indexes). When I query the view, though, it is slow (explain says the scans are sequential). Is this expected or a bug? -- Simulate a table of lead times create view vend_v_lead as select p.pnum as pnum,'vend' as type,ldtime::float8 as lead,0 as aging from vend_price v, prd_part p where v.pnum = p.pnum union select p.pnum,'hist',date_part('day',(m.tdate::datetime-m.mtr_date::datetime)::timespan),0 from mtr_reg m, prd_part p where m.pnum = p.pnum and m.ttype = 'po' and m.status = 'clsd' ; --------------0A04642A3C58B2AC79884C54 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Tom Lane wrote:
> Here's another twist though.  Is this a bug too or is this just beyond our reach?

> psql:lead1.sql:64: ERROR:  Unable to select an aggregate function avg(date)

It's just that we don't have any avg() function for date --- nor for
timestamp, which is a little more surprising.
 

FYI:
I got by with kind of a pseudo average (mean, I guess) for now implemented as:

min(date) + (max(date) - min(date)/2)
 

 
You could probably gin up a usable avg(timestamp) using the avg(float8)
routines, since a timestamp is really just a double under the hood.
 
When you say "gin up" are you talking about C, PL/XXX, or just casts?
 
 

BTW, here's another question:

Here's a view of a union.  The two selects are fast when executed individually (and explain confirms that they use indexes).  When I query the view, though, it is slow (explain says the scans are sequential).

Is this expected or a bug?

-- Simulate a table of lead times
create view vend_v_lead as select
    p.pnum as pnum,'vend' as type,ldtime::float8 as lead,0 as aging from vend_price v, prd_part p where v.pnum = p.pnum
    union select
    p.pnum,'hist',date_part('day',(m.tdate::datetime-m.mtr_date::datetime)::timespan),0 from mtr_reg m, prd_part p where m.pnum = p.pnum and m.ttype = 'po' and m.status = 'clsd'
;
 
  --------------0A04642A3C58B2AC79884C54-- --------------29FE3A9ED2E949B086304C63 Content-Type: text/x-vcard; charset=us-ascii; name="kyle.vcf" Content-Transfer-Encoding: 7bit Content-Description: Card for Kyle Content-Disposition: attachment; filename="kyle.vcf" begin:vcard n:Bateman;Kyle x-mozilla-html:FALSE org:Action Target Inc. adr:;;;;;; version:2.1 email;internet:kyle@actarg.com title:President x-mozilla-cpt:;0 fn:Kyle Bateman end:vcard --------------29FE3A9ED2E949B086304C63--