Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delay execution of SQL script in Amazon Redshift

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?

like image 978
stech Avatar asked Feb 22 '17 21:02

stech


People also ask

What is redshift lag?

The LAG window function returns the values for a row at a given offset above (before) the current row in the partition.

Why is redshift query so slow?

Dataset size – A higher volume of data in the cluster can slow query performance for queries, because more rows need to be scanned and redistributed. You can mitigate this effect by regular vacuuming and archiving of data, and by using a predicate to restrict the query dataset.

How do you stop query execution in redshift?

To cancel a running query, use the CANCEL command with the query's PID. To find the process ID, start a new session and query the STV_RECENTS table, as shown in the previous step.


1 Answers

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);
like image 116
systemjack Avatar answered Sep 19 '22 10:09

systemjack