tags:

views:

60

answers:

2

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, Sharadov

A: 

Not to my knowledge.

You could do something in the shell, piping your SQL through a simple script and then into PostgreSQL. E.g. 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

BTW: I see you asked a very similar question before. It would be nice if you could accept the answers you found solved your problem:

http://stackoverflow.com/questions/1307735/begin-commit-every-50-rows

Jamie Love
Gratuitous use of cat(1)! :) See http://sial.org/howto/shell/useless-cat/
pilcrow
I included the cat as the source of the SQL may quite easily not be a file, but be generated by another program or shell script, so the structure of the command could easily be altered.But I take your point in general.
Jamie Love
Hmm, not sure why you got the downvote -- stylistic uses of cat aside. ;-) If I had an upvote for every time I filtered SQL statements through perl/awk/you-name-it to get the behavior I wanted, I'd be Jon Skeet. +1
pilcrow
+3  A: 

Does pgsql have a waitfor statement like t-sql.

Yes, pg_sleep:

pg=> SELECT pg_sleep(10);
 pg_sleep 
----------

(1 row)
pilcrow