Re: First Aggregate Funtion?

Поиск
Список
Период
Сортировка
От Mike Rylander
Тема Re: First Aggregate Funtion?
Дата
Msg-id b918cf3d0603311735v5dde21d4pfcd613c09d80cf57@mail.gmail.com
обсуждение исходный текст
Ответ на Re: First Aggregate Funtion?  (Martijn van Oosterhout <kleptog@svana.org>)
Ответы Re: First Aggregate Funtion?  (sudalai <sudalait2@gmail.com>)
Список pgsql-hackers
On 3/31/06, Martijn van Oosterhout <kleptog@svana.org> wrote:
> On Fri, Mar 31, 2006 at 03:02:47PM -0600, Tony Caduto wrote:
> > Has there ever been any talk of adding a first aggregate function?
> > It would make porting from Oracle and Access much easier.
> >
> > Or is there something in the contrib modules that I might have missed?
>
> There are several oracle compatability modules:
>
> http://pgfoundry.org/projects/oracompat/
> http://pgfoundry.org/projects/orafce/
>
> I'm sure there's many more if you look...

If all you want is FIRST() and LAST() then:

-- Create a function that always returns the first non-NULL item
CREATE OR REPLACE FUNCTION public.first_agg ( anyelement, anyelement )
RETURNS anyelement AS $$       SELECT CASE WHEN $1 IS NULL THEN $2 ELSE $1 END;
$$ LANGUAGE SQL STABLE;

-- And then wrap an aggreagate around it
CREATE AGGREGATE public.first (       sfunc    = public.first_agg,       basetype = anyelement,       stype    =
anyelement
);

-- Create a function that always returns the last non-NULL item
CREATE OR REPLACE FUNCTION public.last_agg ( anyelement, anyelement )
RETURNS anyelement AS $$       SELECT $2;
$$ LANGUAGE SQL STABLE;

-- And then wrap an aggreagate around it
CREATE AGGREGATE public.last (       sfunc    = public.last_agg,       basetype = anyelement,       stype    =
anyelement
);


Hope that helps!

--
Mike Rylander
mrylander@gmail.com
GPLS -- PINES Development
Database Developer
http://open-ils.org


В списке pgsql-hackers по дате отправления:

Предыдущее
От: David Fetter
Дата:
Сообщение: Re: Suggestion: Which Binary?
Следующее
От: Neil Conway
Дата:
Сообщение: Re: listen not schema-aware