pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

Custom aggregates are silently dropped from the dump

Open saosebastiao opened this issue 7 months ago • 0 comments

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 AGGREGATE statement is NOT captured at all (no aggregates/ directory, no AGGREGATE entry anywhere).
  • Subsequent pgschema plan against 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 a DROP 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.

saosebastiao avatar Apr 27 '26 20:04 saosebastiao