Tha*_*yTy 2 postgresql plpgsql
我想看看 postgres 中 DO 块内的循环迭代需要多长时间。基本布局如下:
DO $$
declare v_time timestamptz;
declare i record;
begin
for i in select generate_series(1, 5) t
loop
select current_timestamp into v_time;
perform pg_sleep(i.t);
-- something done here (pg_sleep to ensure some time passes)
raise notice '%', v_time - (select current_timestamp);
-- expect negative interval from RAISE.
end loop;
end; $$;
Run Code Online (Sandbox Code Playgroud)
但是,当我运行此命令时(已在 Postgres 13 和 9 上尝试过),我得到返回 0S 的间隔:
NOTICE: 00:00:00
NOTICE: 00:00:00
NOTICE: 00:00:00
NOTICE: 00:00:00
NOTICE: 00:00:00
DO
Query returned successfully in 15 secs 389 msec.
Run Code Online (Sandbox Code Playgroud)
我以前做过这个,以前从未遇到过这个问题,所以我想我的问题是“这次我做错了什么?” 而不是“为什么 postgres 的行为异常?”
| 归档时间: |
|
| 查看次数: |
968 次 |
| 最近记录: |