From: Sabin Coanda <sabin.coanda@deuromedia.ro>
To: pgsql-sql@postgresql.org
Subject: plpgsql language not aware of standard_conforming_strings ?
Date: Mon, 12 Nov 2007 12:20:19 +0200
Message-ID: <fh99cq$2cfn$1@news.hub.org> (raw)
Hi there,
Having standard_conforming_strings = 'on', I build the following scenario.
I request SELECT replace( 'a\b', '\', '\\' ), which get me the result:
replace
---------
a\\b
I'd like to build a function that give me the same result, as:
CREATE OR REPLACE FUNCTION "test"(s varchar)
RETURNS varchar AS
$BODY$
BEGIN
RETURN replace( s, '\', '\\' );
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
But I rises the error:
ERROR: unterminated string
SQL state: 42804
Context: compile of PL/pgSQL function "test" near line 3
Ok, I suppose the function is not aware of standard_conforming_strings =
'on', so I have to change \ with \\. I make the following function:
CREATE OR REPLACE FUNCTION "test"(s varchar) RETURNS varchar AS $BODY$
BEGIN
RETURN replace( s, '\\', '\\\\' );
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
The function is created without errors.
But this is useless because SELECT test( 'a\b' ); returns a\b, and SELECT
test( 'a\\b' ); returns a\\\\b.
How can I get my desired function that means when I call test( 'a\b' ) it
will return 'a\\b' ?
TIA,
Sabin
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: <fh99cq$2cfn$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