How to get definition/source code of an aggregate in PostgreSQL?
I found this related answer useful: Export "Create Aggregate" functions from PostgreSQL But how do I get the CREATE AGGREGATE statement without a GUI client (e.g. with psql command line)? a_horse_with_no_name Something like this, but I'm not sure if this covers all possible ways of creating an aggregate (it definitely does not take the need for quoted identifiers into account) SELECT 'create aggregate '||n.nspname||'.'||p.proname||'('||format_type(a.aggtranstype, null)||') (sfunc = '||a.aggtransfn ||', stype = '||format_type(a.aggtranstype, null) ||case when op.oprname is null then '' else ',