Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of FOREACH IN ARRAY #150

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/pgspot/visitors.py
Original file line number Diff line number Diff line change
@@ -160,6 +160,14 @@ def visit(self, node):
)
if "body" in value:
self.visit(value["body"])
case "PLpgSQL_stmt_foreach_a":
if "expr" in value:
visit_sql(
self.state,
"SELECT " + value["expr"]["PLpgSQL_expr"]["query"],
)
if "body" in value:
self.visit(value["body"])
case "PLpgSQL_stmt_raise":
if "params" in value:
for item in value["params"]:
4 changes: 4 additions & 0 deletions testdata/expected/foreach_array.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PS016: Unqualified function call: format at line 1

Errors: 0 Warnings: 1 Unknown: 0

12 changes: 12 additions & 0 deletions testdata/foreach_array.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DO LANGUAGE plpgsql $$
DECLARE
desired_roles text[] := '{pg_checkpoint,pg_signal_backend,pg_read_all_stats,pg_stat_scan_tables}';
desired_role text;
BEGIN
FOREACH desired_role IN ARRAY desired_roles LOOP
IF pg_catalog.to_regrole(desired_role) IS NOT NULL THEN
EXECUTE format('GRANT %I TO tsdbadmin', desired_role);
END IF;
END LOOP;
END;
$$;