我想在两个日期之间循环,但我的 PL/pgSQL 代码进入无限循环。我想我在这里遗漏了一些东西。
do $$
declare
the_dates date;
begin
select gs from generate_series('2019-11-01'::date, '2012-11-30', '1 day') as gs into the_dates;
loop
raise notice '%', the_dates;
end loop;
end
$$
我应该如何在这两个日期之间循环?
最佳答案
您似乎对循环的语法感到困惑。
这里有两个独立的东西:
- 将零行(因为您的日期向后)选择到日期变量中的查询。
- 一个没有限制的循环,将永远发出通知。
https://www.postgresql.org/docs/current/plpgsql-control-structures.html#PLPGSQL-RECORDS-ITERATING
关于postgresql - PL/pgSQL 无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59027156/