Re: Passing function parameters to regexp_replace

Поиск
Список
Период
Сортировка
От Tim Landscheidt
Тема Re: Passing function parameters to regexp_replace
Дата
Msg-id m3fwjvt7wo.fsf@passepartout.tim-landscheidt.de
обсуждение исходный текст
Ответ на Passing function parameters to regexp_replace  (Leif Biberg Kristensen <leif@solumslekt.org>)
Ответы Re: Passing function parameters to regexp_replace  (Leif Biberg Kristensen <leif@solumslekt.org>)
Список pgsql-sql
Leif Biberg Kristensen <leif@solumslekt.org> wrote:

>> UPDATE sources SET source_text = regexp_replace(source_text,
>> E'n="(.*?)$1(.*?)"', E'n="\\1$2\\2"', 'g') where source_text like
>> '%n="%$2%">%';

> Sorry, I pasted a literal replacement, and substituted the parameters by hand.
> The expression should of course be

> UPDATE sources SET source_text = regexp_replace(source_text,
> E'n="(.*?)$1(.*?)"', E'n="\\1$2\\2"', 'g') where source_text like
> '%n="%$1%">%'

Try:

> UPDATE sources SET source_text = regexp_replace(source_text,
> CONCAT(E'n="(.*?)', $1, E'(.*?)"'), CONCAT(E'n="\\1', $2, '\\2"', 'g') where source_text like
> CONCAT('%n="%', $1, '%">%')

If $1 and $2 (can) include meta characters, you have to es-
cape them properly.
 Please consider that regexp_replace() uses POSIX Regular
Expressions while LIKE uses a different syntax. If possible,
I would replace the LIKE expression with its "~" equivalent
so chances of confusion are minimized.

Tim



В списке pgsql-sql по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Use select and update together
Следующее
От: Leif Biberg Kristensen
Дата:
Сообщение: Re: Passing function parameters to regexp_replace