Re: Dump only functions - Mailing list pgsql-admin

From Vasilis Ventirozos
Subject Re: Dump only functions
Date
Msg-id CAF8jcqrnpeC3-5wr5ydd_TWkLcK-US+DCxPFRG4YE1FODnKmGw@mail.gmail.com
Whole thread Raw
In response to Re: Dump only functions  (Raghavendra <raghavendra.rao@enterprisedb.com>)
List pgsql-admin
Try something like this:

for a in `echo "SELECT p.proname
FROM pg_catalog.pg_proc p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE pg_catalog.pg_function_is_visible(p.oid)
AND n.nspname <> 'pg_catalog'
AND n.nspname <> 'information_schema'"|psql -A -t test`;
do echo "SELECT pg_get_functiondef('$a'::regproc);"|psql -A -t test >$a.function.sql ;done

Worked for me, will give you one file per function , called functionname.function.sql 
i just wrote it so i haven't test it much 

Vasilis Ventirozos



On Wed, Mar 27, 2013 at 7:43 PM, Raghavendra <raghavendra.rao@enterprisedb.com> wrote:
On Wed, Mar 27, 2013 at 10:53 PM, Keith Ouellette <Keith.Ouellette@airgas.com> wrote:

Is there a way to dump only functions to a directory with each function as its own file in SQL format?

AFAIK, there's no direct way to dump each function to a separate file. However, you can use system-defined function or system table to retrieve function structure and then write them to separate file each by using bash or perl scripting.

select prosrc from pg_proc where proname='foo';
or
select pg_get_functiondef('foo(integer)'::regprocedure::oid); 
or 
Use other sources like pg_extractor tools. 

---
Regards,
Raghavendra
EnterpriseDB Corporation

 

 

Thanks,

Keith

 



pgsql-admin by date:

Previous
From: Raghavendra
Date:
Subject: Re: Dump only functions
Next
From: Scott Mead
Date:
Subject: Re: Dump only functions