Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delay or Wait-For Statement

I have a 500,000 line SQL script:

update users set region_id = 9814746 where id = 101 and region_id is null; update users set region_id = 9814731 where id = 102 and region_id is null; update users set region_id = 3470676 where id = 103 and region_id is null; 

I want to INSERT a delay of 10 seconds every 50 lines. Does pgsql have a waitfor statement like t-sql.

Thanks.

like image 408
sharadov Avatar asked Aug 25 '09 22:08

sharadov


People also ask

What is wait for delay in SQL Server?

Using WAITFOR DELAY with a local variable. The following example shows how a local variable can be used with the WAITFOR DELAY option. This stored procedure waits for a variable period of time and then returns information to the user as the elapsed numbers of hours, minutes, and seconds.

How do you delay a query?

WAITFOR DELAY – This option can be used to pause a query for a certain duration of time. Time to pass before a query is executed. For example, we can delay the execution of a query by seconds/ minutes or hours. WAITFOR TIME – Other option to pause a query execution until a specified time of a day is reached.

How do I create a delay in SQL?

In Sql Server to PAUSE OR SLEEP OR WAIT the execution of the script for specified period of time say 10 hours or 10 minutes or 10 seconds or 10 millisecond etc we can use the WAITFOR DELAY command.


1 Answers

Does pgsql have a waitfor statement like t-sql.

Yes, pg_sleep:

pg=> SELECT pg_sleep(10);  pg_sleep  ----------  (1 row) 
like image 150
pilcrow Avatar answered Sep 20 '22 12:09

pilcrow