Drawbacks of using an integer as a bitfield?

Posted by Mark on Stack Overflow See other posts from Stack Overflow or by Mark
Published on 2010-06-16T23:13:14Z Indexed on 2010/06/16 23:22 UTC
Read the original article Hit count: 202

I have a bunch of boolean options for things like "accepted payment types" which can include things like cash, credit card, cheque, paypal, etc. Rather than having a half dozen booleans in my DB, I can just use an integer and assign each payment method an integer, like so

PAYMENT_METHODS = (
    (1<<0, 'Cash'),
    (1<<1, 'Credit Card'),
    (1<<2, 'Cheque'),
    (1<<3, 'Other'),
)

and then query the specific bit in python to retrieve the flag. I know this means the database can't index by specific flags, but are there any other drawbacks?

© Stack Overflow or respective owner

Related posts about django

Related posts about database-design