Function SET clauses except search_path are dropped
Summary
pgschema apply silently drops every function-local SET clause except
search_path. This changes runtime semantics when desired-state DDL contains
settings such as SET TimeZone = 'UTC'.
Confirmed with pgschema 1.12.0. The same limitation is present in the 1.12.1
source: the function IR has a single SearchPath field, introspection selects
only search_path from pg_proc.proconfig, and rendering emits only
SET search_path.
Reproduction
Desired state:
CREATE FUNCTION public.proconfig_repro()
RETURNS text
LANGUAGE sql
STABLE
SET search_path = public
SET TimeZone = 'UTC'
AS $$ SELECT current_setting('TimeZone') $$;
Apply it to an empty PostgreSQL 17 database:
$ pgschema apply ... --file schema.sql --auto-approve --no-color
Plan: 1 to add.
DDL to be executed:
CREATE OR REPLACE FUNCTION proconfig_repro()
RETURNS text
LANGUAGE sql
STABLE
SET search_path = public
AS $$ SELECT current_setting('TimeZone')
$$;
The generated DDL has already omitted SET TimeZone.
Live catalog after apply:
SELECT proconfig
FROM pg_proc
WHERE oid = 'public.proconfig_repro()'::regprocedure;
{search_path=public}
Expected:
{search_path=public,TimeZone=UTC}
Impact
This is not limited to TimeZone: any function-local configuration parameter
other than search_path is outside the current IR and is silently lost from
generated CREATE OR REPLACE FUNCTION statements. Time-zone-sensitive digest or
serialization functions can consequently produce session-dependent results.
Suggested acceptance criteria
- Introspect the complete
pg_proc.proconfigarray. - Preserve it in the normalized function IR without lower-casing or otherwise changing values.
- Diff and render every function-local
SETentry deterministically. - Add a round-trip regression with at least
SET search_pathandSET TimeZoneon the same function. - Ensure
plan -> apply -> planconverges with both settings present.