Bitwise & operator in Snowflake?

442 Views Asked by At

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?

1

There are 1 best solutions below

1
On BEST ANSWER

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