postgresql 延迟或等待声明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1331409/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Delay or Wait-For Statement
提问by sharadov
I have a 500,000 line SQL script:
我有一个 500,000 行的 SQL 脚本:
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
.
我想10
每50
行插入几秒钟的延迟。确实pgsql
有waitfor
像t-sql
.
Thanks.
谢谢。
回答by pilcrow
回答by Thomas C. G. de Vilhena
You could call the pg_sleep
function with the PERFORM
statement since we don't care about returning values:
您可以pg_sleep
使用PERFORM
语句调用函数,因为我们不关心返回值:
PERFORM pg_sleep(10);
回答by Sumit S
As pilcrow says that is the easiest way. If you do not want to see the results back, just turn off display before running pg_sleep like this -->
正如 pilcrow 所说,这是最简单的方法。如果您不想看到返回结果,只需在像这样运行 pg_sleep 之前关闭显示 -->
\pset tuples_only on
select pg_sleep(10) ;
\pset tuples_only off
回答by Jamie Love
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:
您可以在 shell 中做一些事情,通过一个简单的脚本将您的 SQL 用管道传输到 PostgreSQL。例如使用 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:
BTW:我看到你之前问过一个非常相似的问题。如果您能接受您发现解决问题的答案,那就太好了: