2

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 1

7

No, there is no function, trick, or hack.
You have to use the normal operators instead:

SELECT *
FROM MyTable
WHERE SomeCol & (1 << 5) != 0;
Sign up to request clarification or add additional context in comments.

4 Comments

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)
Well, 1 << 0 is the zeroth bit then. So, yes.
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?
That depends on the database schema, the data, the query, the software, and the hardware.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.