From: | Gregory Stark <stark(at)enterprisedb(dot)com> |
---|---|
To: | "Matthew Dennis" <mdennis(at)merfer(dot)net> |
Cc: | "PGSQL" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: aggregate and order by |
Date: | 2007-12-06 20:49:20 |
Message-ID: | 87abonr1kf.fsf@oxford.xeocode.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"Matthew Dennis" <mdennis(at)merfer(dot)net> writes:
> So, my question is if I can have PostgreSQL honor order by clauses such as:
>
> select trip_id, avg_vel(position, pos_time)
> from (select position, pos_time, trip_id from data order by pos_time) sorted_data
>
> Would this in fact guarantee that the rows are passed into the aggregate in
> the order specified?
Yes. AFAIK this isn't covered by the spec but it works in Postgres and we know
there are people depending on it so we wouldn't break it without a big notice
and presumably some replacement.
> Other suggestions/discussions/questions/etc are welcome.
Good luck, this looks pretty painful to get right. Keep in mind you have to
keep all your state in the state data. If you keep a temporary variable
outside that data then your function won't work if it's called twice in the
same query like "select avg_vel(position, pos_time), avg_vel(position2,
pos_time2) from ..."
--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's 24x7 Postgres support!
From | Date | Subject | |
---|---|---|---|
Next Message | Glyn Astill | 2007-12-06 21:07:14 | Replication Monitoring |
Previous Message | Ted Byers | 2007-12-06 20:36:44 | SQL design pattern for a delta trigger? |