Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > Re: Scripting f...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 7 Topic 15503 of 16941
Post > Topic >>

Re: Scripting function definitions as SQL?

by reece@[EMAIL PROTECTED] (Reece Hart) May 11, 2008 at 10:27 PM

On Sun, 2008-05-11 at 06:12 -0700, Postgres User wrote:
> Has anyone written a function that scripts out all the functions in a
> database as full SQL statements (Create Function.....)

You could pg_dump the schema in the "custom" format (-Fc), then call
pg_restore with -l to get the TOC, grep the TOC for functions, and feed
that back into pg_restore with -L. It sounds like a lot, but it's pretty
easy in practice, like so:

$ sudo -u postgres pg_dump -Fc -s mydb >mydb.pgdfc
$ pg_restore -l mydb.pgdfc >mydb.toc
$ grep -E '^[0-9]+; [0-9]+ [0-9]+ FUNCTION' mydb.toc >mydb-fx.toc
$ pg_restore -L mydb-fx.toc mydb.pgdfc 

The output of pg_restore is sql.

This technique is extremely useful for other kinds of schema elements as
well.

-Reece

-- 
Reece Hart, http://harts.net/reece/,
GPG:0x25EC91A0


-- 
Sent via pgsql-general mailing list (pgsql-general@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
 




 7 Posts in Topic:
Scripting function definitions as SQL?
postgres.developer@[EMAIL  2008-05-11 06:12:40 
Re: Scripting function definitions as SQL?
kleptog@[EMAIL PROTECTED]  2008-05-11 15:49:37 
Re: Scripting function definitions as SQL?
postgres.developer@[EMAIL  2008-05-11 11:28:37 
Re: Scripting function definitions as SQL?
depesz@[EMAIL PROTECTED]   2008-05-11 20:43:25 
Re: Scripting function definitions as SQL?
postgres.developer@[EMAIL  2008-05-11 12:08:36 
Re: Scripting function definitions as SQL?
reece@[EMAIL PROTECTED]   2008-05-11 22:27:51 
Re: Scripting function definitions as SQL?
singh.gurjeet@[EMAIL PROT  2008-05-12 12:38:38 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 12:32:22 CDT 2008.