What is the Snowflake equivalent code for While Exists (query)?

Viewed 24

I am trying to migrate a SQL Server Proc to Snowflake. In SQL Server, we have a proc which uses WHILE EXISTS and then Query. But I am unable to figure out the equivalent for Snowflake.

In SQL SERVER

WHILE EXISTS (QUERY)
BEGIN
---
END;

Snowflake Giving Error

WHILE EXISTS (QUERY) do
---
END WHILE;


1 Answers

The Snowflake equivalent is:

BEGIN
   WHILE (EXISTS (SELECT * FROM tab)) DO
      ...
   END WHILE;
END;

Output:

enter image description here


Sidenote: The concept or running something in loop indicates the usage of batch processing like, removing/updating in chunks of X rows at a time to avoid long transaction/transaction log growth.

1:1 code translation may not be best approach when using Snowflake and it possible performing entire operation is single run instead.

Related