Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading