pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #17407: trim trims more than expected
3+ messages / 3 participants
[nested] [flat]

* BUG #17407: trim trims more than expected
@ 2022-02-16 10:13 PG Bug reporting form <noreply@postgresql.org>
  2022-02-16 11:03 ` Re:BUG #17407: trim trims more than expected Sergei Kornilov <sk@zsrv.org>
  2022-02-16 15:12 ` Re: BUG #17407: trim trims more than expected Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 2 replies; 3+ messages in thread

From: PG Bug reporting form @ 2022-02-16 10:13 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: unmesh.joshi126@gmail.com

The following bug has been logged on the website:

Bug reference:      17407
Logged by:          trim combined with substring from pattern for gives inconsistent output
Email address:      unmesh.joshi126@gmail.com
PostgreSQL version: 12.4
Operating system:   Linux 5.15.4-051504-generic
Description:        

Expected output

demo=# select trim ('nextval(''' from
substring('nextval(''database_table_id_seq''::regclass)' from
'%#"%_id_seq#"%' for '#' ));
         btrim         
-----------------------
 database_table_id_seq
(1 row)


Unexpected output

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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re:BUG #17407: trim trims more than expected
  2022-02-16 10:13 BUG #17407: trim trims more than expected PG Bug reporting form <noreply@postgresql.org>
@ 2022-02-16 11:03 ` Sergei Kornilov <sk@zsrv.org>
  1 sibling, 0 replies; 3+ messages in thread

From: Sergei Kornilov @ 2022-02-16 11:03 UTC (permalink / raw)
  To: PG Bug reporting form <noreply@postgresql.org>; +Cc: unmesh.joshi126@gmail.com; pgsql-bugs@lists.postgresql.org

Hello
But why don't you expect such a result?

The letter a was definitely mentioned in the list of characters to trim.

select trim('nextval' from 'auth_table_id_seq');
      btrim       
------------------
 uth_table_id_seq

Is expected result. Probably you need some other string manipulation function. 

regards, Sergei





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #17407: trim trims more than expected
  2022-02-16 10:13 BUG #17407: trim trims more than expected PG Bug reporting form <noreply@postgresql.org>
@ 2022-02-16 15:12 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
  1 sibling, 0 replies; 3+ messages in thread

From: Alvaro Herrera @ 2022-02-16 15:12 UTC (permalink / raw)
  To: unmesh.joshi126@gmail.com; pgsql-bugs@lists.postgresql.org

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)





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2022-02-16 15:12 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-02-16 10:13 BUG #17407: trim trims more than expected PG Bug reporting form <noreply@postgresql.org>
2022-02-16 11:03 ` Sergei Kornilov <sk@zsrv.org>
2022-02-16 15:12 ` Alvaro Herrera <alvherre@alvh.no-ip.org>

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