Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHJE4-0004z0-PK for pgsql-bugs@arkaria.postgresql.org; Wed, 22 Nov 2017 00:49:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHJE4-00060K-3V for pgsql-bugs@arkaria.postgresql.org; Wed, 22 Nov 2017 00:49:16 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eHJE3-00060A-Rw for pgsql-bugs@lists.postgresql.org; Wed, 22 Nov 2017 00:49:16 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eHJE1-0007hi-La for pgsql-bugs@postgresql.org; Wed, 22 Nov 2017 00:49:14 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id vAM0nBJS009525; Tue, 21 Nov 2017 19:49:11 -0500 From: Tom Lane To: jorsol@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14920: TEXT binding not works correctly with BPCHAR In-reply-to: <20171122002543.1468.39211@wrigleys.postgresql.org> References: <20171122002543.1468.39211@wrigleys.postgresql.org> Comments: In-reply-to jorsol@gmail.com message dated "Wed, 22 Nov 2017 00:25:43 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <9523.1511311751.1@sss.pgh.pa.us> Date: Tue, 21 Nov 2017 19:49:11 -0500 Message-ID: <9524.1511311751@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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