Passing function parameters to regexp_replace

From: Leif Biberg Kristensen <leif(at)solumslekt(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: Passing function parameters to regexp_replace
Date: 2011-09-17 11:21:43
Message-ID: 201109171321.43309.leif@solumslekt.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Leif Biberg Kristensen 2011-09-17 11:31:58 Re: Passing function parameters to regexp_replace
Previous Message Tim Landscheidt 2011-09-16 23:55:57 Re: Window function sort order help