I noticed that DB2 does not support bitwise operations but I found
some UDFs that seem to give this functionality..
There seems to be a consensus that bitoperations are not usefull (or
bad practice) in sql.. but I am currious though,
say I have a table with a few columns..
attribute_color, attributegroup_2, attributegroup_3....
each one storing a bitstring defining the which of a bunch of values
this attribute contains..
for example...
a choice of (red, yellow, blue, green) can be stored as 0011 (in
attribute_color) if blue and green are the selected colors.. this
makes counting attribute combinations very simple and efficiant over a
lot of rows..
if I wanted to know which items are blue AND green I could simply do a
select count(*) from attribute_table where attribute_color BITAND 11
== 11...
likewise all green colors can be counted with attribute_color BITAND
01=01..
for a large number of attributes and options and adhoc counts of
attribute combinations this works very well.. confining all the data
to one row.
I realise that the software has to keep track of bit positions and
meanings.. but thats little to worry about considering the trade off
between this method and lots of joins or pivoting attribute tables,
is it not?
is this a poor method of storing attributes (that belong to a
multivalue group) ? seems to work nice and fast...
Can someone tell me why this is bad practice? and why is it that there
are no built in BIT operations to do this?
thanks,
Vasili