Re: A query that doesn't work on 7.1

From: Kyle <kyle(at)actarg(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: A query that doesn't work on 7.1
Date: 2001-03-09 00:21:22
Message-ID: 3AA82201.C22A5BAB@actarg.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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'
;

Attachment Content-Type Size
kyle.vcf text/x-vcard 185 bytes

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2001-03-09 00:39:23 Re: A query that doesn't work on 7.1
Previous Message David Olbersen 2001-03-08 23:20:08 explain EXPLAIN?