pgschema
pgschema copied to clipboard
Custom aggregates are silently dropped from the dump
Severity: High (data-impact: would drop the aggregate's transition function on apply, breaking dependent queries).
Repro:
-- In the source DB:
CREATE OR REPLACE FUNCTION myschema._helper(input geometry[]) RETURNS geometry
LANGUAGE plpgsql AS $$ ... $$;
CREATE OR REPLACE AGGREGATE myschema.my_agg(GEOMETRY) (
SFUNC = array_append,
STYPE = GEOMETRY[],
FINALFUNC = myschema._helper,
INITCOND = '{}'
);
pgschema dump --multi-file --schema myschema --file /tmp/dump/main.sql --host ... --db ...
Expected: dump captures both the helper function AND the CREATE AGGREGATE
statement.
Actual:
- The transition/final-function (
_helper) is captured. - The
CREATE AGGREGATEstatement is NOT captured at all (noaggregates/directory, no AGGREGATE entry anywhere). - Subsequent
pgschema planagainst the source DB notices the helper function isn't in desired state (because the user removed it after dumping, OR because the dump never had it) and emits aDROP FUNCTION, which Postgres refuses due to pg_depend on the aggregate.
Suggested fix: include CREATE AGGREGATE statements in --multi-file
output (could go in a new aggregates/ directory under each schema dir)
and recognize them in plan/apply.