Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dbAkF-0000mF-Ea for pgsql-bugs@arkaria.postgresql.org; Fri, 28 Jul 2017 19:16:19 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dbAkF-0005pJ-1U for pgsql-bugs@arkaria.postgresql.org; Fri, 28 Jul 2017 19:16:19 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dbAjW-0003Gt-7e for pgsql-bugs@postgresql.org; Fri, 28 Jul 2017 19:15:34 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dbAjS-0007xV-UF for pgsql-bugs@postgresql.org; Fri, 28 Jul 2017 19:15:33 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v6SJFSYN028070; Fri, 28 Jul 2017 15:15:28 -0400 From: Tom Lane To: Brad DeJong cc: pgsql-bugs@postgresql.org Subject: Re: behavior difference in character literal vs national character literal In-reply-to: References: Comments: In-reply-to Brad DeJong message dated "Fri, 28 Jul 2017 11:38:38 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <28068.1501269327.1@sss.pgh.pa.us> Date: Fri, 28 Jul 2017 15:15:27 -0400 Message-ID: <28069.1501269327@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Brad DeJong 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