Re: Proposal/design feedback needed: WITHIN GROUP (sql standard ordered set aggregate functions) - Mailing list pgsql-hackers

From Josh Berkus
Subject Re: Proposal/design feedback needed: WITHIN GROUP (sql standard ordered set aggregate functions)
Date
Msg-id 51E86F5E.2070107@agliodbs.com
Whole thread Raw
In response to Proposal/design feedback needed: WITHIN GROUP (sql standard ordered set aggregate functions)  (Andrew Gierth <andrew@tao11.riddles.org.uk>)
List pgsql-hackers
> The problem is, given that the parser is looking at:
> 
>   foo(p1,p2,...) within group (order by q1,q2,...)
> 
> how do we best represent the possible matching functions in pg_proc
> and pg_aggregate? Our partial solution so far does not allow
> polymorphism to work properly, so we need a better way; I'm hoping for
> some independent suggestions before I post my own ideas.

Yeah, you'd need to extend VARIADIC somehow.  That is, I should be able
to define a function as:

percentile_state (pctl float,ordercols VARIADIC ANY )
returns VARIADIC ANY

... so that it can handle the sorting.  Another way to look at it would be:

percentile_state (pctl float,orderedset ANONYMOUS ROW )
returns ANONYMOUS ROW as ...

... because really, what you're handing the state function is an
anonymous row type constructed of the order by phrase.  Of course, then
we have to have some way to manipulate the anonymous row from within the
function; at the very least, an equality operator.

-- 
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com



pgsql-hackers by date:

Previous
From: Andrew Gierth
Date:
Subject: Re: Proposal/design feedback needed: WITHIN GROUP (sql standard ordered set aggregate functions)
Next
From: Greg Smith
Date:
Subject: Re: Performance Improvement by reducing WAL for Update Operation