Bit-Strings - Is there a more succinct way to do this?

From: "David Johnston" <polobo(at)yahoo(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Bit-Strings - Is there a more succinct way to do this?
Date: 2011-08-12 23:42:24
Message-ID: 005701cc5949$7eeda550$7cc8eff0$@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Making use of my first Bit-String and need see which records in a table have
at least one position match with a user-supplied comparison string. The
following query is what I am using to do the comparison.

SELECT *

FROM (VALUES (B'010',B'01000')) src (vs_bitmap_stock, vs_bitmap_sale)

WHERE

((vs_bitmap_stock & '110'::bit(3) )::integer > 0 AND

(vs_bitmap_sale & '11000'::bit(5))::integer > 0)

Also, my source data is actually stored in multiple Boolean fields and I am
using the following in a trigger to create a comparable BitString.

NEW.vs_bitmap_stock = (NEW.bool1::integer::text || NEW.bool2::integer::text
|| NEW.bool3::integer::text)::bit(3)

While both are functional they seem to be somewhat obtuse due to all of the
casting. The Bit-String sections of the Data Types, Functions & Operators,
sections seem pretty sparse. I know the concept isn't that difficult so
either I am not doing things in the expected way or the implementation
doesn't directly support the use-case I have in mind.

Thanks for any pointers.

David J.

Browse pgsql-general by date

  From Date Subject
Next Message c k 2011-08-13 15:35:08 Re: postgresql server crash on windows 7 when using plpython
Previous Message Rich Shepard 2011-08-12 22:46:58 Re: COPY from .csv File and Remove Duplicates [RESOLVED]