From: "Tom Lane" <tgl@sss.pgh.pa.us>
> Yeah, this is a fairly obvious thing to want to do with a user-written
> aggregate. It does not work in released versions, because the planner
> does not notice that the inner SELECT's output ordering matches what
> the GROUP BY needs, and so it inserts an additional Sort plan step
> above the sub-select (you can see this if you look at EXPLAIN output).
> Unfortunately, on most platforms qsort() isn't stable and will not
> preserve the ordering of its input for equal keys. So you lose the
> minor ordering by seq_no in the re-sort.
Most grateful for the rapid response Tom. Knowing that, I can work around by
iterating through the firs at the application level.
Regards
Julian Scarfe
PS: you shouldn't be working on a Sunday, it's bad for you ;-)