pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: 甄明洋 <zhenmingyang@yeah.net>
To: pgsql-bugs@lists.postgresql.org
Subject: The result of the pattern matching is incorrect when the pattern string is bpchar type
Date: Thu, 11 Jul 2019 18:48:11 +0800 (CST)
Message-ID: <68c3aa88.331d9.16be0a5d184.Coremail.zhenmingyang@yeah.net> (raw)

There are two tables with the type of column is char. when Using a 'like' predicate in a join condition will result in an incorrect result. 
Because  there is no 'like' operator that left operand and right operand are all bpchar.(bpchar ~~ bpchar), final the operator 'bpchar ~~ text' will be found form candidate set. so database do the cast from bpchar to text, The space at the end of the string was removed during the cast.


1、Following a example:
postgres=# create table t1(a char(6));
CREATE TABLE
postgres=# create table t2(a char(6));
CREATE TABLE
postgres=# insert into t1 values('aaa');
INSERT 0 1
postgres=# insert into t2 values('aaa');
INSERT 0 1
postgres=# select * from t1, t2 where t1.a=t2.a;
   a    |   a
--------+--------
 aaa    | aaa
(1 row)


postgres=# select * from t1, t2 where t1.a like t2.a;
 a | a
---+---
(0 rows)
postgres=#


2、The following example is a comparative:
postgres=# select 'aaa'::text like 'aaa'::text;
 ?column?
----------
 t
(1 row)


postgres=# select 'aaa'::char(6) like 'aaa'::char(6);
 ?column?
----------
 f
(1 row)
postgres=#

view thread (3+ messages)  latest in thread

Message-ID: <68c3aa88.331d9.16be0a5d184.Coremail.zhenmingyang@yeah.net>
Permalink:  ../68c3aa88.331d9.16be0a5d184.Coremail.zhenmingyang@yeah.net/
Also on:    postgresql.org/message-id/68c3aa88.331d9.16be0a5d184.Coremail.zhenmingyang@yeah.net

 · 

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: zhenmingyang@yeah.net
  Subject: Re: The result of the pattern matching is incorrect when the pattern string is bpchar type
  In-Reply-To: <68c3aa88.331d9.16be0a5d184.Coremail.zhenmingyang@yeah.net>
  References: <68c3aa88.331d9.16be0a5d184.Coremail.zhenmingyang@yeah.net>

* 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