pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: jorsol@gmail.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #14920: TEXT binding not works correctly with BPCHAR
Date: Tue, 21 Nov 2017 19:49:11 -0500
Message-ID: <9524.1511311751@sss.pgh.pa.us> (raw)
In-Reply-To: <20171122002543.1468.39211@wrigleys.postgresql.org>
References: <20171122002543.1468.39211@wrigleys.postgresql.org>

jorsol@gmail.com writes:
> TEXT type is the preferred data type for the category String, but I'm having
> a hard time using it with bpchar:

I believe what you're showing here can be reduced to these cases:

regression=# select 'c'::char(3) = 'c'::text;
 ?column? 
----------
 t
(1 row)

regression=# select 'c'::char(3) = 'c  '::text;
 ?column? 
----------
 f
(1 row)

That is, the = operator is resolved as text = text, for which
trailing spaces in the strings are significant.  But when we
promote the bpchar value to text, we strip its trailing spaces,
which are deemed not significant.  So we have 'c' = 'c' and
'c' != 'c  '.

regression=# select 'c'::char(3) = 'c'::varchar;
 ?column? 
----------
 t
(1 row)

regression=# select 'c'::char(3) = 'c  '::varchar;
 ?column? 
----------
 t
(1 row)

Here, the = operator is resolved as bpchar = bpchar, in which
trailing spaces aren't significant period.

I forget at the moment exactly why these choices of how to resolve
the ambiguous comparison operator get made, but most likely it has
to do with text being a preferred type while varchar hasn't even
got any operators of its own.  Reading the type conversions chapter
of the manual would help you identify why that happens.

These behaviors are of long standing and we're very unlikely to
change them.  If you don't like them, don't use bpchar; it's a
legacy datatype of little real value anyway.

			regards, tom lane




view thread (3+ messages)  latest in thread

Message-ID: <9524.1511311751@sss.pgh.pa.us>
Permalink:  ../9524.1511311751@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/9524.1511311751@sss.pgh.pa.us

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jorsol@gmail.com
  Subject: Re: BUG #14920: TEXT binding not works correctly with BPCHAR
  In-Reply-To: <9524.1511311751@sss.pgh.pa.us>
  References: <20171122002543.1468.39211@wrigleys.postgresql.org> <9524.1511311751@sss.pgh.pa.us>

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

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