On Thu, Dec 15, 2011 at 10:10 AM, Robert James <srobertjames@gmail.com> wrote:
> I see Postgres (I'm using 8.3) has bitwise aggregate functions
> (bit_or), but doesn't seem to have logical aggregate functions.
>
> How do I do the equivalent of an ANY() or ALL() in PG Aggregate SQL?
CREATE OR REPLACE FUNCTION OrAgg(bool, bool) RETURNS BOOL AS
$$
SELECT COALESCE($1 or $2, false);
$$ LANGUAGE SQL IMMUTABLE;
create aggregate "any"(bool)
(
sfunc=OrAgg,
stype=bool
);
postgres=# select "any"(v) from (values (false), (true)) q(v);
any
-----
t
(1 row)
etc
note:, I don't like the use of double quoted "any" -- but I'm too lazy
to come up with a better name. :-)
merlin