Following this answer I learnt that I can disable syntax checking for an SQL function by setting check_function_bodies=false
.
In my case: Running an upgrade using Flyway where
My question is - is it possible to issue a "recheck" of such a function without having to actually call it - once all other dependencies are in place?
Something similar to Oracle's alter function ... compile
.
Ideally I would like to set check_function_bodies=false
at the beginning of the upgrade and then recheck every SQL function at the end of it.
I want to avoid having to:
Things I tried:
alter function
pg_get_functiondef
I can think of two ways:
You can call the language validator function directly:
SELECT lanname, lanvalidator::regprocedure FROM pg_language;
lanname | lanvalidator
------------+------------------------------
internal | fmgr_internal_validator(oid)
c | fmgr_c_validator(oid)
sql | fmgr_sql_validator(oid)
plpgsql | plpgsql_validator(oid)
plpython3u | plpython3_validator(oid)
(5 rows)
For SQL functions, that would work like this:
SET check_function_bodies = off;
CREATE FUNCTION bad() RETURNS void LANGUAGE sql AS 'SELECT $1';
SET check_function_bodies = on;
SELECT fmgr_sql_validator('bad()'::regprocedure);
ERROR: there is no parameter $1
LINE 1: SELECT $1
^
QUERY: SELECT $1
You can redefine the function and check if it throws an error:
SET check_function_bodies = on;
DO $$BEGIN
EXECUTE pg_get_functiondef('bad()'::regprocedure);
END;$$;