Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id B34B337C6BA for ; Mon, 12 Nov 2007 06:43:50 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 17929-06 for ; Mon, 12 Nov 2007 06:43:44 -0400 (AST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by postgresql.org (Postfix) with ESMTP id 0F7F237C678 for ; Mon, 12 Nov 2007 06:43:50 -0400 (AST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.1/8.14.1) with ESMTP id lACAhkdo083129 for ; Mon, 12 Nov 2007 06:43:46 -0400 (AST) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.1/8.14.1/Submit) id lACAKBCk078328 for pgsql-sql@postgresql.org; Mon, 12 Nov 2007 06:20:11 -0400 (AST) (envelope-from news) From: "Sabin Coanda" X-Newsgroups: pgsql.sql Subject: plpgsql language not aware of standard_conforming_strings ? Date: Mon, 12 Nov 2007 12:20:19 +0200 Organization: Hub.Org Networking Services Lines: 48 Message-ID: X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-RFC2646: Format=Flowed; Original To: pgsql-sql@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/50 X-Sequence-Number: 29578 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