On 11/1/26 7:13 AM, Ron Johnson wrote:
On Sun, Nov 1, 2026 at 1:43 AM Igor Korot <[email protected] <mailto:[email protected]>> wrote:

    hi, ALL,
    Is there an option to return a trimmed string from the query?

    If I try to retrieve the char(10) from the table and the field only have
    "abc", how to prevent the value to be returned as "abc     "?



TRIM() is the portable/standards method:
SELECT TRIM(TRAILING ' ' FROM a) FROM foo;

*TRIM removes spaces by default so the ' ' is not necessary((length thrown in to prove trim):

select trim(TRAILING 'abc  '), length(trim(TRAILING'abc  '));
 rtrim | length
-------+--------
 abc   |      3


Even shorter would be::

select rtrim('abc  '), length(rtrim('abc  '));

rtrim | length
-------+--------
 abc   |      3


There are many useful string functions:
https://www.postgresql.org/docs/17/functions-string.html <https:// www.postgresql.org/docs/17/functions-string.html>

--
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!


--
Adrian Klaver
[email protected]


Reply via email to