Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id AD4B9B5DBCE for ; Sat, 17 Sep 2011 08:22:07 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 16160-04 for ; Sat, 17 Sep 2011 11:21:57 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from mail48.e.nsc.no (mail48.e.nsc.no [193.213.115.48]) by mail.postgresql.org (Postfix) with ESMTP id 9268FB5DBC8 for ; Sat, 17 Sep 2011 08:21:55 -0300 (ADT) Received: from balapapa.localnet (107.100.202.84.customer.cdi.no [84.202.100.107]) (authenticated bits=0) by mail48.nsc.no (8.14.4/8.14.4) with ESMTP id p8HBLhVJ026843 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Sat, 17 Sep 2011 13:21:44 +0200 (MEST) From: Leif Biberg Kristensen To: pgsql-sql@postgresql.org Subject: Passing function parameters to regexp_replace Date: Sat, 17 Sep 2011 13:21:43 +0200 User-Agent: KMail/1.13.7 (Linux/2.6.39-gentoo-r3; KDE/4.6.5; x86_64; ; ) MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <201109171321.43309.leif@solumslekt.org> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201109/37 X-Sequence-Number: 35837 I'm trying to write a sql or plpgsql function update_nametags(TEXT, TEXT) which does a replace on this form: UPDATE sources SET source_text = regexp_replace(source_text, E'n="(.*?)$1(.*?)"', E'n="\\1$2\\2"', 'g') where source_text like '%n="%$2%">%'; But I can't find out how to escape the parameters $1 and $2. I've also tried to wrap it in an EXECUTE and concatenate the parameters with no luck. I'd also like to have the function return the number of affected rows. regards, Leif