Subject: What is the meaning of the N string operator ?

From: Danilo Fortunato <[email-masked]>
Date: Sun, 07 Jun 2015 22:44:18 +0200

In the SQL code related to Greenplum Database (which is based on 
PostgreSQL) generated by a query and reporting tool, a noticed a "N" 
operator put before a lot of strings.
For example:

case  when column_a <> N'#' then column_a
       when column_b <> N'#' then column_b
       else NULL
end

I executed this SQL code, and I found out that it is valid.

In the PostgreSQL documentation I didn't find a description of this 
operator (though it is not easy to search for).
However, I found a description of the E (escape) and B (binary) string 
operators.

Can anybody explain the meaning of the N string operator ?
Is there a section in the PostgreSQL documentation that describes it ?

Thanks,
Danilo Fortunato

-- 
Sent via pgsql-docs mailing list ([email-masked])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-docs

---

From: Andreas Seltenreich <[email-masked]>
Date: Sun, 07 Jun 2015 23:32:43 +0200

> Is there a section in the PostgreSQL documentation that describes it ?

I couldn't find it in the manual either, but using it seems to yield
values of type char instead of varchar/text:

,----
| scratch=# select N'foo   ';
|  bpchar 
| --------
|  foo   
| 
| scratch=# \dT bpchar
|                                 List of data types
|    Schema   |   Name    |                       Description                       
| ------------+-----------+---------------------------------------------------------
|  pg_catalog | character | char(length), blank-padded string, fixed storage length
`----

In contrast to the N'' input syntax, the blank-padding type itself is
documented under "Character Types" and leads to different semantics with
various operators/functions.  E.g.:

,----
| scratch=# select length(N'foo   '), length('foo   ');
|  length | length 
| --------+--------
|       3 |      6
| (1 row)
`----

regards,
Andreas

---

From: Tom Lane <[email-masked]>
Date: Sun, 07 Jun 2015 17:37:21 -0400

> Can anybody explain the meaning of the N string operator ?

The SQL standard says that N'foo' is a literal of the data type NATIONAL
CHARACTER.  PG supports this syntax (and the type name) but treats it the
same as plain character/varchar.

> Is there a section in the PostgreSQL documentation that describes it ?

I don't see it offhand.  I think it's pretty much useless/deprecated
anyway so I'm not sure it's worth documenting.

			regards, tom lane

---

From: Danilo Fortunato <[email-masked]>
Date: Sun, 14 Jun 2015 21:56:55 +0200

Thanks a lot for your support.

Danilo