pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Sabin Coanda <sabin.coanda@deuromedia.ro>
To: pgsql-sql@postgresql.org
Subject: Re: plpgsql language not aware of standard_conforming_strings ?
Date: Mon, 12 Nov 2007 18:19:13 +0200
Message-ID: <fh9udq$1n50$1@news.hub.org> (raw)
References: <fh99cq$2cfn$1@news.hub.org>
	<fh9cbj$2pd2$1@news.hub.org>


"Sabin Coanda" <sabin.coanda@deuromedia.ro> wrote in message 
news:fh9cbj$2pd2$1@news.hub.org...
>
> "Sabin Coanda" <sabin.coanda@deuromedia.ro> wrote in message 
> news:fh99cq$2cfn$1@news.hub.org...
> ...
>>
>> 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 





view thread (3+ messages)

Message-ID: <fh9udq$1n50$1@news.hub.org>
Permalink:  ../fh9udq$1n50$1@news.hub.org/
Also on:    postgresql.org/message-id/fh9udq$1n50$1@news.hub.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sabin.coanda@deuromedia.ro
  Subject: Re: plpgsql language not aware of standard_conforming_strings ?
  In-Reply-To: <fh9udq$1n50$1@news.hub.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox