Re: Logical Aggregate Functions (eg ANY()) - Mailing list pgsql-general

From Merlin Moncure
Subject Re: Logical Aggregate Functions (eg ANY())
Date
Msg-id CAHyXU0w-JHEPxj6EZ4QHEDcknKpV6QmdN8MA_K1c884OZT46AQ@mail.gmail.com
Whole thread Raw
In response to Logical Aggregate Functions (eg ANY())  (Robert James <srobertjames@gmail.com>)
List pgsql-general
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

pgsql-general by date:

Previous
From: Raymond O'Donnell
Date:
Subject: Re: Streaming Replication Configuration
Next
From: Eliot Gable
Date:
Subject: LOCK DATABASE