If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > PostgreSQL > How to escape $ signs in plpgsql function?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-28-11, 04:56
sidukas sidukas is offline
Registered User
 
Join Date: Jun 2011
Posts: 11
How to escape $ signs in plpgsql function?

Is there any way to use $BODY$ in the string? If I am renaming it to $BODY1$ or any other - it is working, but can I use $BODY$ somehow?

Code:
CREATE OR REPLACE FUNCTION test_function()
  RETURNS character varying AS
$BODY$
DECLARE
        dyn_sql    varchar(5000):='';
BEGIN
 dyn_sql = '$BODY$';
return dyn_sql;
END
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ERROR: unterminated quoted string at or near "';
return dyn_sql;
END
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;

"
LINE 8: dyn_sql = '$BODY$';
^

********** Error **********

ERROR: unterminated quoted string at or near "';
return dyn_sql;
END
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;

"
SQL state: 42601
Character: 153
Reply With Quote
  #2 (permalink)  
Old 06-28-11, 15:06
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,408
You can use anything for $BODY$, so the following should work:
Code:
CREATE OR REPLACE FUNCTION test_function()
  RETURNS character varying AS
$PROC$
DECLARE
        dyn_sql    varchar(5000):='';
BEGIN
 dyn_sql = '$BODY$';
return dyn_sql;
END
$PROC$
  LANGUAGE plpgsql VOLATILE
  COST 100;
Reply With Quote
  #3 (permalink)  
Old 06-29-11, 03:49
sidukas sidukas is offline
Registered User
 
Join Date: Jun 2011
Posts: 11
I know that. But can I use $BODY$ in both places?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On