Is there an function, trick, hack to make a query that only retrieves values from a table where an integer field has a special bit set?
1 Answer
No, there is no function, trick, or hack.
You have to use the normal operators instead:
SELECT *
FROM MyTable
WHERE SomeCol & (1 << 5) != 0;
4 Comments
prom85
Am I interpreting your example correctly: this query will select all rows where the column
SomeCol has the fifth bit set? (shifting 1 5 bits left and combine this via a binary AND with the column, meaning this is true, if the 5th bit is set in SomeCol)CL.
Well,
1 << 0 is the zeroth bit then. So, yes.prom85
So your answer is actually what I was looking for. Did not know that I can do that in a query directly. Do you know if those operators are efficient? Or should I use multiple columns instead if possible?
CL.
That depends on the database schema, the data, the query, the software, and the hardware.