textlike under the LIKE operator for char(n)

Поиск
Список
Период
Сортировка
От Kohei KaiGai
Тема textlike under the LIKE operator for char(n)
Дата
Msg-id CADyhKSWPosAgqLbaZB6sDEmFQNW8oKZkuPL9=qBz=q=8D_fygw@mail.gmail.com
обсуждение исходный текст
Ответы Re: textlike under the LIKE operator for char(n)  (Kevin Grittner <kgrittn@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: "Daniel Verite"
Дата:
Сообщение: Re: \crosstabview fixes
Следующее
От: Mithun Cy
Дата:
Сообщение: Perf Benchmarking and regression.