Passing a String with special character as an input

From: akp geek <akpgeek(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Passing a String with special character as an input
Date: 2010-11-23 20:34:39
Message-ID: AANLkTi=uC8D-LthyrM7JCK_OoQN2HY1YMyHObGc_BGTm@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi -

This is related to my earlier post. For the function I am passing
a string. But the string some time has a single quote inside the string like
"IT's a String Test" , How can I handle that, can you please help?

CREATE OR REPLACE FUNCTION test_repl(x character varying)
RETURNS character varying AS
$BODY$
DECLARE
ret_var varchar(4000);
a record;
begin
ret_var := x;

for a in select * from lookup
loop
ret_var := replace(ret_var,a.code,a.codeword);
end loop;
return ret_var;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
ALTER FUNCTION test_repl(character varying) OWNER TO postgres;

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dan Kortschak 2010-11-23 20:40:37 Re: very basic SQL question
Previous Message Pavel Stehule 2010-11-23 20:32:30 Re: Problem with replace function in postgres