@@ -17,6 +17,7 @@ declare
1717 prepared_statement_name text = ' index_advisor_working_statement' ;
1818 hypopg_schema_name text = (select extnamespace::regnamespace::text from pg_extension where extname = ' hypopg' );
1919 explain_plan_statement text ;
20+ error_message text ;
2021 rec record;
2122 plan_initial jsonb;
2223 plan_final jsonb;
@@ -35,17 +36,12 @@ begin
3536 -- Remove trailing semicolon
3637 query := regexp_replace(query, ' ;\s *$' , ' ' );
3738
38- -- Disallow multiple statements
39- if query ilike ' %;%' then
40- return query values (
41- null ::jsonb,
42- null ::jsonb,
43- null ::jsonb,
44- null ::jsonb,
45- array[]::text [],
46- array[' Query must not contain a semicolon' ]::text []
47- );
48- else
39+ begin
40+ -- Disallow multiple statements
41+ if query ilike ' %;%' then
42+ raise exception ' Query must not contain a semicolon' ;
43+ end if;
44+
4945 -- Hack to support PostgREST because the prepared statement for args incorrectly defaults to text
5046 query := replace(query, ' WITH pgrst_payload AS (SELECT $1 AS json_data)' , ' WITH pgrst_payload AS (SELECT $1::json AS json_data)' );
5147
8783 select
8884 distinct objid as oid
8985 from
90- pg_depend
86+ pg_catalog . pg_depend
9187 where
9288 deptype = ' e'
9389 )
@@ -108,7 +104,7 @@ begin
108104 on pc .oid = pa .attrelid
109105 left join extension_regclass er
110106 on pc .oid = er .oid
111- left join pg_index pi
107+ left join pg_catalog . pg_index pi
112108 on pc .oid = pi .indrelid
113109 and (select array_agg(x) from unnest(pi .indkey ) v(x)) = array[pa .attnum ]
114110 and pi .indexprs is null -- ignore expression indexes
@@ -174,8 +170,21 @@ begin
174170 statements::text [],
175171 array[]::text []
176172 );
173+ return;
177174
178- end if;
175+ exception when others then
176+ get stacked diagnostics error_message = MESSAGE_TEXT;
177+
178+ return query values (
179+ null ::jsonb,
180+ null ::jsonb,
181+ null ::jsonb,
182+ null ::jsonb,
183+ array[]::text [],
184+ array[error_message]::text []
185+ );
186+ return;
187+ end;
179188
180189end;
181190$$;
0 commit comments