public inbox for [email protected]  
help / color / mirror / Atom feed
From: PG Doc comments form <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: BPCHAR description in 8.3. Character Types is misleading and incomplete
Date: Tue, 14 Oct 2025 12:14:53 +0000
Message-ID: <[email protected]> (raw)

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/18/datatype-character.html
Description:

The description of BPCHAR in section 8.3. Character Types is misleading and
incomplete.
The first problem is that, contrary to table 8.4, BPCHAR is not actually
blank-trimmed. The wording "as-if-blank-trimmed" or "blank-ignoring" may be
better suited here. The following query explains the problem:

SELECT bpchar_val, length(bpchar_val) as bplen, concat('[', bpchar_val, ']')
as bpbrack
        , varchar_val, length(varchar_val) as vclen, concat('[',
varchar_val, ']') as vcbrack
FROM (VALUES
        ('abc   '::bpchar, 'abc   '::varchar),
        ('abc   '::bpchar, 'abc'::varchar),
        ('abc'::bpchar, 'abc   '::varchar),
        ('abc'::bpchar, 'abc'::varchar))
AS bpchar_test (bpchar_val, varchar_val)
WHERE bpchar_val = varchar_val;

As can be seen, it returns four rows (so, it indeed treats values that
differ only in number of trailing spaces as equal, regardless of the type on
the other side, and the length of bpchar_val is always 3 in all 4 rows -
trailing spaces are ignored in comparison. But the bpbrack column shows that
actual value is NOT trimmed: two of four rows have '[abc   ]' value (with 3
spaces before the closing bracket).
The example above also illustrate the need of more detailed explanation of
how BPCHAR actually behaves in different situation, particularly, in which
contexts trailing blanks are ignored (comparison, length, what else?) and in
which they are still significant (displaying, client interfaces,
concatenation, what else?).

The second problem is that 'Tip' before the example 8.1 mentions only three
types, also in a misleading way: 'There is no performance difference among
these three types' - as if there were only 3, not 4 distinct types.


reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: BPCHAR description in 8.3. Character Types is misleading and incomplete
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox