From: Tom Lane <tgl@sss.pgh.pa.us>
To: Brad DeJong <bpd0018@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: behavior difference in character literal vs national character literal
Date: Fri, 28 Jul 2017 15:15:27 -0400
Message-ID: <28069.1501269327@sss.pgh.pa.us> (raw)
In-Reply-To: <CAJnrtnwyYxBcBhe0W04Nq3Godx0Ch3PyC-OVPREkGf_0jGztJw@mail.gmail.com>
References: <CAJnrtnwyYxBcBhe0W04Nq3Godx0Ch3PyC-OVPREkGf_0jGztJw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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
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: tgl@sss.pgh.pa.us, bpd0018@gmail.com
Subject: Re: behavior difference in character literal vs national character literal
In-Reply-To: <28069.1501269327@sss.pgh.pa.us>
References: <CAJnrtnwyYxBcBhe0W04Nq3Godx0Ch3PyC-OVPREkGf_0jGztJw@mail.gmail.com> <28069.1501269327@sss.pgh.pa.us>
* 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