1

I am trying to write a snowflake UDF that sleeps for 60 seconds and then runs. Is this possible to define within a UDF?

Something like

CREATE OR REPLACE FUNCTION MY_FUNCTION()
RETURNS INT
AS 
$$
--- sleeps for 60 seconds
--- executes function/does something

$$;

Thanks.

Anonymous
  • 25
  • 3

1 Answers1

2

Using SYSTEM$WAIT:

CREATE OR REPLACE FUNCTION MY_FUNCTION()
RETURNS INT
AS 
$$
SELECT 1
FROM (SELECT SYSTEM$WAIT(60))
$$;

SELECT MY_FUNCTION();

Note: Placing side-effect inside functions is not a good practice.

It is not guaranteed that function is run only once, so it is possible it will last long longer than anticipated:

SELECT MY_FUNCTION()
FROM big_table_here;
Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275