Re: plpgsql language not aware of standard_conforming_strings ?

From: "Sabin Coanda" <sabin(dot)coanda(at)deuromedia(dot)ro>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: plpgsql language not aware of standard_conforming_strings ?
Date: 2007-11-12 16:19:13
Message-ID: fh9udq$1n50$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


"Sabin Coanda" <sabin(dot)coanda(at)deuromedia(dot)ro> wrote in message
news:fh9cbj$2pd2$1(at)news(dot)hub(dot)org(dot)(dot)(dot)
>
> "Sabin Coanda" <sabin(dot)coanda(at)deuromedia(dot)ro> wrote in message
> news:fh99cq$2cfn$1(at)news(dot)hub(dot)org(dot)(dot)(dot)
> ...
>>
>> How can I get my desired function that means when I call test( 'a\b' ) it
>> will return 'a\\b' ?
>>
>
...

> CREATE OR REPLACE FUNCTION myreplace(sText varchar, sSrc varchar, sDst
...

Unfortunatelly this is not very productive when sSrc or sDst has to be
constants inside the function. There is another workaround for that, to
specify '\' as chr(92). For instance:

CREATE OR REPLACE FUNCTION myformat(sText varchar) RETURNS varchar AS
$BODY$
BEGIN
RETURN replace( sText, chr(92), '\\' );
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;

Consequently, the statement SELECT myformat('a\b' ) will get the desired
result a\\b

Sabin

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Sabin Coanda 2007-11-12 17:12:36 Re: show value of backslashes in string array argument
Previous Message Tom Lane 2007-11-12 16:05:27 Re: show value of backslashes in string array argument