9
votes

Does Redshift have any functions similar to pg_sleep() in PostgreSQL?

I have a SQL script that needs to wait for some time before continuing with the execution.

The Unsupported PostgreSQL Functions Redshift documentation that says pg_sleep() is not supported.

Update 1:

I am running into deadlock issue in Redshift. I have multiple processes that can query a table (or set of tables) with DROP/TRUNCATE/INSERT/UPDATE/SELECT. If there is a deadlock, I was trying to catch this exception and have the process wait for sometime and retry. Are there any recommendations on ways to handle deadlocks?

2
Does it just need to wait for a certain duration, or does it need to wait until some external event has (hopefully) happened?John Rotenstein
Yeah, are you worried about eventual consistency or some similar case?systemjack
Forcing your script to wait is almost always the wrong thing to do - what is your use case i.e. why do you want to sleep?saille

2 Answers

8
votes

A sketchy not recommended approach is to use a Python User Defined Function:

CREATE OR REPLACE FUNCTION janky_sleep (x float) RETURNS bool IMMUTABLE as $$
    from time import sleep
    sleep(x)
    return True
$$ LANGUAGE plpythonu;

select janky_sleep(5.0);
0
votes

Have you tried using lock on the table. I have had a similar situation like you, lock on the table helped me over come that.