Re: Logical Aggregate Functions (eg ANY())

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Robert James <srobertjames(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Logical Aggregate Functions (eg ANY())
Date: 2011-12-15 17:05:23
Message-ID: CAHyXU0w-JHEPxj6EZ4QHEDcknKpV6QmdN8MA_K1c884OZT46AQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Dec 15, 2011 at 10:10 AM, Robert James <srobertjames(at)gmail(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Eliot Gable 2011-12-15 17:17:27 LOCK DATABASE
Previous Message Raymond O'Donnell 2011-12-15 16:54:54 Re: Streaming Replication Configuration