pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Leif Biberg Kristensen <leif@solumslekt.org>
To: pgsql-sql@postgresql.org
Subject: Passing function parameters to regexp_replace
Date: Sat, 17 Sep 2011 13:21:43 +0200
Message-ID: <201109171321.43309.leif@solumslekt.org> (raw)

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



view thread (5+ messages)  latest in thread

Message-ID: <201109171321.43309.leif@solumslekt.org>
Permalink:  ../201109171321.43309.leif@solumslekt.org/
Also on:    postgresql.org/message-id/201109171321.43309.leif@solumslekt.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: leif@solumslekt.org
  Subject: Re: Passing function parameters to regexp_replace
  In-Reply-To: <201109171321.43309.leif@solumslekt.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