Open
Description
Describe the problem
EXIT WHEN from a nested FOR .. IN loop may produce an infinite loop.
To Reproduce
When playing around with potential workarounds for #148988, I stumbled upon this:
create or replace procedure "proc_ForIndexedLoopNested"()
language plpgsql
as
$$
begin
for i in 0 .. 1 loop
for j in 1 .. 5 loop
raise notice '%', (("i" * 5) + "j");
exit when j = 4;
end loop;
end loop;
end;
$$
call "proc_ForIndexedLoopNested"();
This just loops forever, printing weird stuff:
1
2
3
4
26
27
28
29
26
27
28
29
26
27
28
29
26
27
28
It may be the same issue as #148988, I can't tell for sure. In case it isn't, I just wanted to report this separately, because it's much worse than #148988, which doesn't produce infinite loops.
Expected behavior
It should print:
1
2
3
4
6
7
8
9
Environment:
- CockroachDB version: CockroachDB CCL v25.2.1 (x86_64-pc-linux-gnu, built 2025/06/02 23:17:23, go1.23.7 X:nocoverageredesign)
- Server OS: Linux on Docker on Windows
- Client app: JDBC
Jira issue: CRDB-51915
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Triage