gpt4 book ai didi

postgresql - PL/pgSQL block 是如何编译的?

转载 作者:行者123 更新时间:2023-11-29 12:44:01 25 4
gpt4 key购买 nike

   do $$
declare
tm1 timestamp without time zone;
tm2 timestamp without time zone;
begin
select localtimestamp(0) into tm1;
for i in 1..200000000 loop
--just waiting several second
end loop;
select localtimestamp(0) into tm2;

raise notice '% ; %', tm1, tm2;
end;
$$ language plpgsql

为什么给这个过程 tm1tm2 相同的值?

这段代码不是一步步执行的吗?

最佳答案

From the manual

These SQL-standard functions all return values based on the start time of the current transaction [...] Since these functions return the start time of the current transaction, their values do not change during the transaction. This is considered a feature: the intent is to allow a single transaction to have a consistent notion of the "current" time, so that multiple modifications within the same transaction bear the same time stamp

(强调我的)

您可能需要 clock_timestamp()

关于postgresql - PL/pgSQL block 是如何编译的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34918758/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com