I need to pull out some data from a PostgreSQL database - namely some old "lost" functions.
I've got a select statement which pulls up the function name as column1, and the function definition as column2.
Is there any easy (or, for that matter, difficult) way to automagically create a filename with the name column1, and dump the contents of column2 to that file?
Ideally this would be on a one-file-per-row export, although I suppose if I can output it to a single file I can create a quick script to split it to individual files
Any pointers appreciated!
Thanks
Edit:
I've tried the following
SELECT pg_get_functiondef(f.oid)) INTO OUTFILE proname
FROM pg_catalog.pg_proc f
INNER JOIN pg_catalog.pg_namespace n ON (f.pronamespace = n.oid)
WHERE n.nspname = 'my_namespace'
The select works fine without the INTO OUTFILE... clause, but I get a syntax error with that clause. This is whether I use the proname, or a '/tmp/test.sql' type file path.