"Jim C. Nasby" <jim@nasby.net> writes:
> Am I just being naive, or couldn't this be solved by adding min/max
> boolean flags to pg_aggregates and the appropriate syntax to CREATE
> AGGREGATE?
I'd prefer to see a direct link to the associated sort operator
('<' for MIN or '>' for MAX). But yeah, some addition to the system
catalogs seems essential if you don't want the code to be full of
unsupportable assumptions about aggregate and operator names.
> So it seems the ORDER/LIMIT hack doesn't work well at all except in
> limited situations.
No kidding. This is one reason there hasn't been a huge push to get it
implemented: the actual usefulness of the hack is quite limited. In
your example, I suspect the presence of the unrelated WHERE clause is
what makes it unhelpful.
regards, tom lane