Re: BUG #17407: trim trims more than expected

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: unmesh(dot)joshi126(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17407: trim trims more than expected
Date: 2022-02-16 15:12:38
Message-ID: 202202161512.tsbczybuwa3i@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 2022-Feb-16, PG Bug reporting form wrote:

> Unexpected output
>
> demo=# select trim ('nextval(''' from
> substring('nextval(''auth_table_id_seq''::regclass)' from '%#"%_id_seq#"%'
> for '#' ));
> btrim
> ------------------
> uth_table_id_seq

Not a bug. trim() receives a *set* of characters to remove, not a
*substring* to remove, so the 'a' in 'auth' is matched to the 'a' in
'nextval(' and gets removed.

You can probably achieve what you want by combining substring() with
position() and char_length(), or by using a regular expression in
regexp_replace().

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"La conclusión que podemos sacar de esos estudios es que
no podemos sacar ninguna conclusión de ellos" (Tanenbaum)

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2022-02-16 15:37:50 Re: Report a potential memory leak in setup_config()
Previous Message PG Bug reporting form 2022-02-16 14:38:55 BUG #17409: Unable to alter data type of clustered column which is referenced by foreign key