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 dc15ca0
Showing 1 changed file with 3 additions and 3 deletions.
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 dc15ca0

Please sign in to comment.