Re: Return trimmed string from the query

From: Igor Korot <ikorot01(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Return trimmed string from the query
Date: 2026-11-05 02:56:25
Message-ID: CA+FnnTwCus_FgF0Q-r_BXBf6V1CDnAV6mbXLK+Ua=Bs7c7MnmA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-odbc

Hi,

On Sun, Nov 1, 2026 at 12:03 AM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>
> Hi
>
> ne 1. 11. 2026 v 7:43 odesílatel Igor Korot <ikorot01(at)gmail(dot)com> napsal:
>>
>> 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 "?
>
>
> no, there is not any option, you need to cast result value to varchar;
>
> (2026-11-01 07:57:03) postgres=# create table foo(a char(10));
> CREATE TABLE
> (2026-11-01 08:01:49) postgres=# insert into foo values('abc');
> INSERT 0 1
> (2026-11-01 08:02:03) postgres=# select a, a::varchar from foo;
> ┌────────────┬─────┐
> │ a │ a │
> ╞════════════╪═════╡
> │ abc │ abc │
> └────────────┴─────┘

Sorry for a late reply.

So does this mean that if I use varchar instead of char I will not
have this problem?

Thank you,

> (1 row)
>
> regards
>
> Pavel
>
>>
>>
>> Thank you.
>>
>>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ron Johnson 2026-11-05 03:48:33 Re: Application Error When Accessing the Table – PostgreSQL 15.18
Previous Message loganathan P 2026-11-05 02:53:05 Re: Application Error When Accessing the Table – PostgreSQL 15.18

Browse pgsql-odbc by date

  From Date Subject
Next Message Rob Sargent 2026-11-05 04:48:09 Re: Return trimmed string from the query
Previous Message hubert depesz lubaczewski 2026-11-02 12:10:42 Re: Return trimmed string from the query