Function to dump function ddl

From: "Little, Douglas" <DOUGLAS(dot)LITTLE(at)orbitz(dot)com>
To: "PostgreSQL General (pgsql-general(at)postgresql(dot)org)" <pgsql-general(at)postgresql(dot)org>
Subject: Function to dump function ddl
Date: 2012-08-09 17:06:24
Message-ID: 8585BA53443004458E0BAA6134C5A7FBAFBC825D@EGEXCMB01.oww.root.lcl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,
In deploying new versions of function source, I want to export the current definition to a file.
After looking around it seems that I needed to create my own function.

I got the function to work, but am having a slight problem with the execution of the exported file.
It seems that if I include line breaks they are not being interpreted by psql on input.

Other than leaving the line breaks out, does anybody have any suggestions for getting psql to ignore the line feeds.
I tried to replace the \n with blanks on output, but failed.

Some specifics might help.
Running on redhat, pg 8.2.15/greenplum 4.1.2.6

Ddl export
d1gp1=> \copy (SELECT dba_work.pg_get_functiondef('da_test.aggairbookingitinasbookedprc'::regproc)) to test1.sql
d1gp1=>

exported file
[dlittle(at)eginformatica02p ~]$ cat test1.sql
\nCREATE OR REPLACE FUNCTION da_test.aggairbookingitinasbookedprc(numeric)\nRETURNS void AS\n$BODY$\n\n/* Declare Variables*/\n-- modified 2/28/2010\nDECLARE\n vTimestamp TIMESTAMP(6); -- Variable to Store Current Timestamp during diffent process stage.\n vAuditKey VARCHAR(18); -- Variable to Capture Lastest Auditkey for Specific Dimension Processing.\n vSpStep INTEGER;

Import
d1gp1=> \i test1.sql
psql:test1.sql:1: invalid command \nCREATE
d1gp1=>

--
Replacing \n attempt
d1gp1=> \copy (select replace(dba_work.pg_get_functiondef('da_test.aggairbookingitinasbookedprc'::regproc),E'\n',' ')) to test1.sql WARNING: nonstandard use of escape in a string literal
LINE 1: ...test.aggairbookingitinasbookedprc' ::regproc ) ,E '\n' , ' '...
^
HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.
ERROR: type "e" does not exist
LINE 1: ...a_test.aggairbookingitinasbookedprc' ::regproc ) ,E '\n' , '...
^
\copy: ERROR: type "e" does not exist
LINE 1: ...a_test.aggairbookingitinasbookedprc' ::regproc ) ,E '\n' , '...

d1gp1=> \copy (select replace(dba_work.pg_get_functiondef('da_test.aggairbookingitinasbookedprc'::regproc),'\\n',' ')) to test1.sql WARNING: nonstandard use of \\ in a string literal
LINE 1: ..._test.aggairbookingitinasbookedprc' ::regproc ) , '\\n' , ' ...

Doug Little

Sr. Data Warehouse Architect | Business Intelligence Architecture | Orbitz Worldwide
500 W. Madison, Suite 1000 Chicago IL 60661| Office 312.260.2588 | Fax 312.894.5164 | Cell 847-997-5741
Douglas(dot)Little(at)orbitz(dot)com<mailto:Douglas(dot)Little(at)orbitz(dot)com>
[cid:image001(dot)jpg(at)01CD7625(dot)A87D1690] orbitz.com<http://www.orbitz.com/> | ebookers.com<http://www.ebookers.com/> | hotelclub.com<http://www.hotelclub.com/> | cheaptickets.com<http://www.cheaptickets.com/> | ratestogo.com<http://www.ratestogo.com/> | asiahotels.com<http://www.asiahotels.com/>

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Geert Mak 2012-08-09 17:09:05 documentation — version switch
Previous Message Kevin Grittner 2012-08-09 16:35:03 Re: Slow query