Delay or confirmation of expectation

I have 500,000 lines of 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. Pgsql has a waitfor command such as t-sql.

Thanks.

+7
postgresql
source share
3 answers

Pgsql has a waitfor command such as t-sql.

Yes pg_sleep :

 pg=> SELECT pg_sleep(10); pg_sleep ---------- (1 row) 
+17
source share

You can call the pg_sleep function with the PERFORM , since we do not need the return values:

 PERFORM pg_sleep(10); 
+1
source share

As I know.

You can do something in the shell by running your SQL through a simple script and then in PostgreSQL. For example. with Perl:

 cat regionupdates.sql | perl -e '$i = 1; while(<STDIN>) { $i++; print $_; if ($i % 50 == 0) { sleep 10; } }' | psql -d MYDB -L output.txt 

By the way: I see that you asked a very similar question before. It would be nice if you agreed to answer the answers you found:

Start ... complete every 50 lines

0
source share

All Articles