Skip to content

Commit

Permalink
Add handling for plpgsql LOOP and EXIT
Browse files Browse the repository at this point in the history
  • Loading branch information
svenklemm committed Oct 8, 2024
1 parent 2da7637 commit c3d12ad
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/pgspot/visitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ def visit(self, node):
self.state,
"SELECT " + value["expr"]["PLpgSQL_expr"]["query"],
)
case "PLpgSQL_stmt_exit":
if "cond" in value:
visit_sql(
self.state,
"SELECT " + value["cond"]["PLpgSQL_expr"]["query"],
)
case "PLpgSQL_stmt_if":
if "cond" in value:
visit_sql(
Expand Down Expand Up @@ -169,6 +175,9 @@ def visit(self, node):
)
if "body" in value:
self.visit(value["body"])
case "PLpgSQL_stmt_loop":
if "body" in value:
self.visit(value["body"])
case "PLpgSQL_stmt_raise":
if "params" in value:
for item in value["params"]:
Expand Down
6 changes: 6 additions & 0 deletions testdata/expected/loop.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PS002: Unsafe function creation: l() at line 1
PS005: Function without explicit search_path: l() at line 1
PS016: Unqualified function call: f1 at line 1

Errors: 0 Warnings: 3 Unknown: 0

11 changes: 11 additions & 0 deletions testdata/loop.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
create or replace function l() returns void as $func$
declare
begin
loop
end loop;
loop
PERFORM f1('select 1');
exit when true;
end loop;
end
$func$ language plpgsql;

0 comments on commit c3d12ad

Please sign in to comment.