Re: ltrim function - Mailing list pgsql-bugs

From Joe Conway
Subject Re: ltrim function
Date
Msg-id 51426995-d584-a77c-7a11-2559c2278f24@joeconway.com
Whole thread Raw
List pgsql-bugs
On 12/12/19 6:15 PM, Serdar Başyiğit wrote:
> select ltrim('TRYTND', 'TRY’); — result is ND but I expected TND
> select ltrim('TRYUSD', 'TRY’); — result is USD it is same what I expect

This is working as documented. See:
https://www.postgresql.org/docs/current/functions-string.html

Specifically:
----
Function  ltrim(string text [, characters text])
Returns   text
Desc      Remove the longest string containing
          only characters from characters (a space
          by default) from the start of string     Example
ltrim('zzzytest', 'xyz')
Result    test
----

> Is there some thing that I misunderstood?

Yes, see above.

In the future, please ask questions on pgsql-general list before
assuming there is a bug. And please do not post HTML email -- ASCII only
here.

What you might want instead of what you are doing is something like:

select replace('TRYTND', 'TRY', '');
 replace
---------
 TND
(1 row)

Of course that only works if there are not other instances of TRY in
your strings. Or perhaps better:

select
 regexp_replace('TRYTNDTRY2 TRY TRY', '^TRY', '');
 regexp_replace
-----------------
 TNDTRY2 TRY TRY
(1 row)

See here for more info:
https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-POSIX-REGEXP

HTH,

Joe

--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development


Attachment

pgsql-bugs by date:

Previous
From: Jeff Janes
Date:
Subject: Re: BUG #16162: create index using gist_trgm_ops leads to panic
Next
From: Tomas Vondra
Date:
Subject: Re: BUG #16162: create index using gist_trgm_ops leads to panic