Re: behavior difference in character literal vs national character literal

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Brad DeJong <bpd0018(at)gmail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: behavior difference in character literal vs national character literal
Date: 2017-07-28 19:15:27
Message-ID: 28069.1501269327@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Brad DeJong <bpd0018(at)gmail(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Scott Milliken 2017-07-28 19:35:27 Re: BUG #14758: Segfault with logical replication on a function index
Previous Message Alvaro Herrera 2017-07-28 19:02:01 Re: signal 11 segfaults with parallel workers