Re: BPCHAR description in 8.3. Character Types is misleading and incomplete - Mailing list pgsql-docs

From Sergei Katkovsky
Subject Re: BPCHAR description in 8.3. Character Types is misleading and incomplete
Date
Msg-id CAAf8JyLJDtbBnx7zc_oPb=16YAHH0PyAh5H_GtZ7R0QJPqthNQ@mail.gmail.com
Whole thread Raw
In response to Re: BPCHAR description in 8.3. Character Types is misleading and incomplete  (Laurenz Albe <laurenz.albe@cybertec.at>)
Responses Re: BPCHAR description in 8.3. Character Types is misleading and incomplete
List pgsql-docs
On Fri, Oct 17, 2025 at 4:49 PM Laurenz Albe <laurenz.albe@cybertec.at> wrote:

> "bpchar" and "varchar", when used without type modifier, are actually
> identical:
>
> SELECT octet_length(BPCHAR 'x   '),
>        octet_length(VARCHAR 'x   '),
>        octet_length(TEXT 'x   ');
>
>  octet_length │ octet_length │ octet_length
> ══════════════╪══════════════╪══════════════
>             4 │            4 │            4
>
> The blank-trimming only occurs when a "bpchar" is converted to "text",
> for example when used with the concatenation operator.

Unfortunately, BPCHAR and VARCHAR are not identical in other contexts.
The situation is not the same as with BCHAR(n), which is just an alias
for CHAR(n).
SELECT BPCHAR 'x' = VARCHAR 'x   ', VARCHAR 'x' = BPCHAR 'x   ',
VARCHAR 'x' = VARCHAR 'x   ';
true true false
For comparison with BPCHAR trailing blanks are insignificant, but when
we have VARCHAR on both sides, they matter.

With best regards,
Sergei Katkovskii



pgsql-docs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: BPCHAR description in 8.3. Character Types is misleading and incomplete
Next
From: Sergei Katkovsky
Date:
Subject: Re: BPCHAR description in 8.3. Character Types is misleading and incomplete