postgresql - PL/pgSQL 无限循环
问题描述
我想在两个日期之间循环,但我的 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
推荐阅读
- sql - 当 unpivot 未检测到具有不同类型的字段时,雪花如何转换选择查询的所有字段?
- java - 使用信号量开发同步算法
- python - 多次运行脚本时出现 Python 错误:模块“__main__”没有属性“__spec__”
- jenkins - Jenkins - 通过证书进行代理身份验证
- python - 在获取熊猫数据框的行之间的差异时填充 NaN
- java - Minecraft 服务器无效的 plugin.yml
- c# - DTO 的泛型列表
- php - 使用 PHP 在图像上居中多行文本
- python - 为什么使用漂亮的汤找不到某些链接
- erpnext - 如何在列表视图中为子项指定过滤器?