textlike under the LIKE operator for char(n) - Mailing list pgsql-hackers

From Kohei KaiGai
Subject textlike under the LIKE operator for char(n)
Date
Msg-id CADyhKSWPosAgqLbaZB6sDEmFQNW8oKZkuPL9=qBz=q=8D_fygw@mail.gmail.com
Whole thread Raw
Responses Re: textlike under the LIKE operator for char(n)  (Kevin Grittner <kgrittn@gmail.com>)
List pgsql-hackers
Hi,

I found a mysterious behavior when we use LIKE operator on char(n) data type.


postgres=# select 'abcd'::char(20) LIKE 'ab%cd';?column?
----------f
(1 row)

postgres=# select 'abcd'::char(4) LIKE 'ab%cd';?column?
----------t
(1 row)

LIKE operator (that is eventually processed by textlike) considers the
padding space of char(n) data type as a part of string.

On the other hands, equal operator ignores the padding space when it
compares two strings.

postgres=# select 'abcd'::char(20) = 'abcd';?column?
----------t
(1 row)

postgres=# select 'abcd'::char(4) = 'abcd';?column?
----------t
(1 row)

The LIKE operator on char(n) data type is implemented by textlike().

at pg_proc.h:
DATA(insert OID = 1631 (  bpcharlike       PGNSP PGUID 12 1 0 0 0 f f
f f t f i s 2 0 16 "1042 25" _null_ _null_ _null_ _null_ _null_
textlike _null_ _null_ _null_ ));

It calls GenericMatchText() with length of the target string,
calculated by VARSIZE_ANY_EXHDR, however, it includes the padding
space.
It seems to me bcTruelen() gives the correct length for char(n) data
types, instead of this macro.

Is this behavior as expected? or, bug?

Thanks,
-- 
KaiGai Kohei <kaigai@kaigai.gr.jp>



pgsql-hackers by date:

Previous
From: "Daniel Verite"
Date:
Subject: Re: \crosstabview fixes
Next
From: Mithun Cy
Date:
Subject: Perf Benchmarking and regression.