'Bitwise & operator in Snowflake?

I'm stuck with Snowflake about bitwise operators. In MySql it's allowed to use this syntax:

Flag & 1024 > 0

I'd like to make the same filtering in the where clause with Snowflake but I've found only these function on the web: https://docs.snowflake.com/en/sql-reference/expressions-byte-bit.html

Do you have any ideal how to do the same thing?



Solution 1:[1]

The Flag & 1024 > 0 is equivalent of BITWISE AND:

WHERE BITAND(Flag, 1024) > 0;

db<> fiddle demo MySQL

Snowflake:

CREATE TABLE tab(flag INT)
AS
SELECT 1024 AS flag
UNION SELECT 2048
UNION SELECT 1025;

SELECT *
FROM tab
WHERE BITAND(Flag, 1024) > 0;
-- 1024
-- 1025

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1