Contents
ltrim()
A system function which trims characters from the left side of a string
ltrim()
is a system function which trims specified characters (default: spaces) from the left side of a string.
ltrim()
was added in PostgreSQL 6.1.
Usage
ltrim()
is a convenience/compatibility function equivalent to the SQL standard trim()
:
postgres=# SELECT ltrim('foobar', 'foo'), trim(LEADING 'foo' FROM 'foobar'); ltrim | ltrim -------+------- bar | bar (1 row)
Change history
- PostgreSQL 14
- PostgreSQL 6.1
- added (commit 83978e1e)
Examples
Remove spaces from the left side of a string:
postgres=# SELECT ltrim(' foobar'); ltrim -------- foobar (1 row)
Remove a particular character from the left side of a string:
postgres=# SELECT ltrim('XXXfoobar', 'X'); ltrim -------- foobar (1 row)
A group of characters for removal can be specified; note the removal will stop when the first character not in that group is encountered:
postgres=# SELECT ltrim('X_Zfoobar', 'XZ_'); ltrim -------- foobar (1 row) postgres=# SELECT ltrim('X_Zfoobar', 'XZ'); ltrim ---------- _Zfoobar (1 row)
References
- PostgreSQL documentation: Other String Functions