Re: Bitwise OR in a group statement

From: "Florian G(dot) Pflug" <fgp(at)phlo(dot)org>
To: Greg Gazanian <ggazan(at)ausd(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Bitwise OR in a group statement
Date: 2006-06-22 10:44:29
Message-ID: 449A748D.4090504@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Greg Gazanian wrote:
> I was wondering if anyone happens to know whether there is an Aggregate function available in Postgres that can do an OR on a column of the bit varying type. For example I would like to do something as follows:
>
> bitstring
> *--------
> 1110
> 0100
> 1111
>
> SELECT bitwise_or(bitstring) FROM table;
>
> Resulting in:
> 1111
There is no such function predefined, but you can easily define one
yourself.

create aggregate or_bit64(
basetype=bit,
sfunc=bitor,
stype=bit,
initcond=
'0000000000000000000000000000000000000000000000000000000000000000'
) ;

I'm using this in production, and it works fine. I didn't find a way to
make this length-agnostic, so I defined this for all lenghts of
bitstrings the my app uses (32 and 64).

greetings, Florian Pflug

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Kenneth Downs 2006-06-22 11:24:11 Re: Return the primary key of a newly inserted row?
Previous Message brian ally 2006-06-22 07:51:48 Re: Help from Havana