On 3/31/06, Martijn van Oosterhout <[email protected]> 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
[EMAIL PROTECTED]
GPLS -- PINES Development
Database Developer
http://open-ils.org
---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings