Re: ltrim function

From: Joe Conway <mail(at)joeconway(dot)com>
To: Serdar Başyiğit <serdarbasyigit(at)yandex(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: ltrim function
Date: 2019-12-13 00:08:04
Message-ID: 51426995-d584-a77c-7a11-2559c2278f24@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tomas Vondra 2019-12-13 00:16:18 Re: BUG #16162: create index using gist_trgm_ops leads to panic
Previous Message Jeff Janes 2019-12-13 00:05:53 Re: BUG #16162: create index using gist_trgm_ops leads to panic