Thread: Bit-Strings - Is there a more succinct way to do this?
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.