pgschema
pgschema copied to clipboard
`plpgsql` function body references not included in function dependency ordering
unfortunately it seems like pg_depend doesn't return function-to-function dependencies
-- Base function that parses input (named 'z_helper' so it comes after alphabetically)
CREATE OR REPLACE FUNCTION z_helper_parse(input text)
RETURNS text
LANGUAGE plpgsql
IMMUTABLE
AS $$
BEGIN
RETURN upper(input);
END
$$;
-- SQL function that calls z_helper_parse in its body (named 'a_wrapper' so it comes before alphabetically)
-- SQL functions validate their body at creation time, so z_helper_parse must exist first
-- Without proper dependency ordering, this would be created first and fail
CREATE OR REPLACE FUNCTION a_wrapper_function(input text)
RETURNS boolean
LANGUAGE sql
IMMUTABLE
AS $$
SELECT z_helper_parse(input) = 'TEST';
$$;