Re: Return trimmed string from the query

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Ron Johnson <ronljohnsonjr(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Return trimmed string from the query
Date: 2026-11-01 15:49:26
Message-ID: 36bf0a2d-368f-4c98-bf93-531cb6f868bb@aklaver.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-odbc

On 11/1/26 7:13 AM, Ron Johnson wrote:
> On Sun, Nov 1, 2026 at 1:43 AM Igor Korot <ikorot01(at)gmail(dot)com
> <mailto:ikorot01(at)gmail(dot)com>> 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
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message hubert depesz lubaczewski 2026-11-02 12:10:42 Re: Return trimmed string from the query
Previous Message Ron Johnson 2026-11-01 15:13:18 Re: Return trimmed string from the query

Browse pgsql-odbc by date

  From Date Subject
Next Message hubert depesz lubaczewski 2026-11-02 12:10:42 Re: Return trimmed string from the query
Previous Message Ron Johnson 2026-11-01 15:13:18 Re: Return trimmed string from the query