Skip to content

Commit

Permalink
Reword error messages for pganalyze.explain_analyze helper per feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
lfittl committed Dec 28, 2024
1 parent 8fcc1f9 commit f192625
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions input/postgres/explain_analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var helperTests = []helperTestpair{
[]string{},
[]string{"VERBOSE OFF", "COSTS OFF", "ANALYZE", "TIMING OFF"},
"",
"pq: cannot run pganalyze.explain_analyze helper function when query contains semicolon",
"pq: cannot run helper with a multi-statement query",
},
{
"SELECT $1",
Expand Down Expand Up @@ -102,7 +102,7 @@ var helperTests = []helperTestpair{
[]string{},
[]string{"FORMAT JSON) SELECT 1; UPDATE test SET id = 123; EXPLAIN (COSTS OFF"},
"",
"pq: cannot run pganalyze.explain_analyze helper function with invalid flag",
"pq: cannot run helper with invalid flag",
},
// Cases that are worth documenting by test (but they are not bugs, just things worth noting)
{
Expand Down
6 changes: 3 additions & 3 deletions util/explain_analyze_helper.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ BEGIN

PERFORM 1 FROM pg_roles WHERE (rolname = current_user AND rolsuper) OR (pg_has_role(oid, 'MEMBER') AND rolname IN ('rds_superuser', 'azure_pg_admin', 'cloudsqlsuperuser'));
IF FOUND THEN
RAISE EXCEPTION 'cannot run: pganalyze.explain_analyze helper function is owned by superuser - recreate function with lesser privileged user';
RAISE EXCEPTION 'cannot run: helper is owned by superuser - recreate function with lesser privileged user';
END IF;

SELECT pg_catalog.regexp_replace(query, ';+\s*\Z', '') INTO prepared_query;
IF prepared_query LIKE '%;%' THEN
RAISE EXCEPTION 'cannot run pganalyze.explain_analyze helper function when query contains semicolon';
RAISE EXCEPTION 'cannot run helper with a multi-statement query';
END IF;

explain_prefix := 'EXPLAIN (VERBOSE, FORMAT JSON';
FOR explain_flag IN SELECT * FROM unnest(analyze_flags)
LOOP
IF explain_flag NOT SIMILAR TO '[A-z_ ]+' THEN
RAISE EXCEPTION 'cannot run pganalyze.explain_analyze helper function with invalid flag';
RAISE EXCEPTION 'cannot run helper with invalid flag';
END IF;
explain_prefix := explain_prefix || ', ' || explain_flag;
END LOOP;
Expand Down

0 comments on commit f192625

Please sign in to comment.