Re: ltrim function
Joe Conway <[email protected]> Thu, 12 Dec 2019 19:08:04 -0500
| Newsgroups | gmane.comp.db.postgresql.bugs |
|---|---|
| Message-ID | <[email protected]> |
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
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEg14x9eymXoJyHrH+N/L3QzX32GUFAl3y1mQACgkQN/L3QzX3 2GVswg//e2oRFtNXGMugiYTfHjgUQFqyXrGirFJU2B3B6ImUqe2j5nJLRjS0uQJ2 UQszKcbGeCLp+HLQJxBgrlQHIsDaTQ5u2hkGfssd/AQN7unyF1SV8MPPZ/2RzXu4 8tVQO6oqh+vULw2+tmzLVZm3J8MX5AhJxI133KWjRdOtDd1ZrWz0pkOh03t7IFAV fOa5q+5/CZ2fHnbZNjEccqw+v2bARWztCc++vvVV6eSJ+BScrE4ci9DOqgNy9hWH SzDBxu+6bZqZrYme8cFF2smRYwmXHdVGhVHRVo+I4j7IAbJoL3JNt/8c62xeFONx kg+BQki83KhgoObHTtQ594cDr1wheg3nzElnN46cSnGEWB/gEKA8xg7iBhccMIlf XVTieFuDtcBM1Krxm3Cfg5jaNAlkTZNzByl4uM0tCIRNWQA0q57TxKyZvldzP68d zLQRshedBxQYA+TkPVQvQ7msMlA3tzs98Ysx35+5GK4MibIuFFmBVjOLYabZaaie 0MEDOf5bKdimjFrE18tFVsC/yn90pg3Gn0aZ2DPchCqHDgxM61SFX76DK97yFZki yfHPVY2/p/mrl/Iqx19S3Xf3cSKAzYYaxowQ9WGF+JaCrWmCjdSpyQhKjToFpUQS 5h63hdQFLjvCWWCJ0CygB2Dja7Rwr61ESPWC/EVTiQbW+lMB9Cw= =YwM5 -----END PGP SIGNATURE-----