From: Kyle <kyle@actarg.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-sql@postgresql.org
Subject: Re: A query that doesn't work on 7.1
Date: Thu, 08 Mar 2001 17:21:22 -0700
Message-ID: <3AA82201.C22A5BAB@actarg.com> (raw)
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>
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'
;
Attachments:kyle.vcf (text/x-vcard, 184B) download
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: kyle@actarg.com, tgl@sss.pgh.pa.us
Subject: Re: A query that doesn't work on 7.1
In-Reply-To: <3AA82201.C22A5BAB@actarg.com>
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> <3AA82201.C22A5BAB@actarg.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox