Re: regexp_replace weirdness amounts to a bug?

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: regexp_replace weirdness amounts to a bug?
Date: 2023-08-16 10:07:43
Message-ID: 20230816100743.2l5eva7hufoh3hq3@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2023-Aug-16, Erik Rijkers wrote:

> Hello,
>
> The following surprised me enough to think it might be a bug:
> (17devel)
>
> select
> regexp_replace('Abc Def'
> , '([a-z]) ([A-Z])'
> , '\1 ' || lower('\2') );
>
> regexp_replace
> ----------------
> Abc Def

What's happening here is that the lower() is applying to the literal \2,
and the expansion of \2 to 'D' occurs afterwards, when lower() has
already executed. Note this other example, where the literal part of
the replacement string is correctly lowercased:

select
regexp_replace('Abc Def'
, '([a-z]) ([A-Z])'
, '\1 ' || lower('D\2D'));
regexp_replace
────────────────
Abc dDdef
(1 fila)

I don't know how to achieve what you want.

--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
#error "Operator lives in the wrong universe"
("Use of cookies in real-time system development", M. Gleixner, M. Mc Guire)

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2023-08-16 10:09:33 Re: cataloguing NOT NULL constraints
Previous Message Tomas Vondra 2023-08-16 10:01:01 Re: pg_logical_emit_message() misses a XLogFlush()