Re: [GENERAL] multiple parameters to an AGGREGATE function

2015-01-27 Thread Christian Paminger
Hi, maybe this will help: CREATE OR REPLACE FUNCTION _final_nth( anyarray, integer ) RETURNS anyelement AS $BODY$ SELECT a FROM unnest( $1 ) a ORDER BY a offset $2 LIMIT 1; $BODY$ USE it without an extra aggregate-function. SELECT _final_nth(array_agg(someelement),n) AS someelement FROM so

Re: [GENERAL] multiple parameters to an AGGREGATE function

2012-02-03 Thread Merlin Moncure
On Fri, Feb 3, 2012 at 11:27 AM, Graham wrote: > Hi, >   first time poster here ... > > I'm trying to write a simple Aggregate function which returns the nth > element in a collection - ultimately I want to find 95th, 90th percentiles > and so on. > > It'd be called like: > > select nth_element( v

[GENERAL] multiple parameters to an AGGREGATE function

2012-02-03 Thread Graham
Hi, first time poster here ... I'm trying to write a simple Aggregate function which returns the nth element in a collection - ultimately I want to find 95th, 90th percentiles and so on. It'd be called like: select nth_element( value, 95 ) from something group by ... I'm basing this on an e