Re: Proposal/design feedback needed: WITHIN GROUP (sql standard ordered set aggregate functions)

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
Cc: PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Proposal/design feedback needed: WITHIN GROUP (sql standard ordered set aggregate functions)
Date: 2013-07-18 22:42:38
Message-ID: 51E86F5E.2070107@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tatsuo Ishii 2013-07-18 22:45:21 Re: [PATCH] pgbench --throttle (submission 7 - with lag measurement)
Previous Message Greg Smith 2013-07-18 22:40:48 Re: Performance Improvement by reducing WAL for Update Operation