Re: [BUGS] behavior difference in character literal vs national character literal

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [BUGS] behavior difference in character literal vs national character literal
Дата
Msg-id 28069.1501269327@sss.pgh.pa.us
обсуждение исходный текст
Ответ на [BUGS] behavior difference in character literal vs national character literal  (Brad DeJong <bpd0018@gmail.com>)
Список pgsql-bugs
Brad DeJong <bpd0018@gmail.com> writes:
> Given that PostgreSQL is silently converting NCHAR, NCHAR VARYING, ... to
> CHAR, CHAR VARYING, ... it seems to me like national character literals
> should also silently convert to character literals - with exactly the same
> behavior in regards to trimming of trailing spaces during casts to ::text.

But ' ' without any decoration IS NOT a character literal.  It's a literal
of unknown type, which in cases like this will ultimately default to text,
but in other cases will be deemed to have other types.  N/NCHAR, on the
other hand, defines what the data type is, just as much as if you'd
written an explicit cast.

regression=# select 'a' || char ' ' || 'b';?column? 
----------ab
(1 row)

regression=# select 'a' || nchar ' ' || 'b';?column? 
----------ab
(1 row)

regression=# select 'a' || char varying ' ' || 'b';?column? 
----------a b
(1 row)

regression=# select 'a' || nchar varying ' ' || 'b';?column? 
----------a b
(1 row)

I don't see anything wrong there.  You can certainly quibble with our
basic choice to strip trailing blanks when converting from char to
varchar/text, but NCHAR isn't doing anything different from CHAR.
        regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: [BUGS] signal 11 segfaults with parallel workers
Следующее
От: Scott Milliken
Дата:
Сообщение: Re: [BUGS] BUG #14758: Segfault with logical replication on afunction index