12

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?

3
  • Does it just need to wait for a certain duration, or does it need to wait until some external event has (hopefully) happened? Commented Feb 22, 2017 at 23:24
  • Yeah, are you worried about eventual consistency or some similar case? Commented Feb 23, 2017 at 1:01
  • 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? Commented Feb 23, 2017 at 4:21

2 Answers 2

15

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);
Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

How did you create that lock?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.