What is the meaning of the N string operator ?

Поиск
Список
Период
Сортировка
Искать

What is the meaning of the N string operator ?

От:
Danilo Fortunato <danilo.fortunato.2@gmail.com>
Дата:
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

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

От:
Andreas Seltenreich <seltenreich@gmx.de>
Дата:
Danilo Fortunato writes:

> Can anybody explain the meaning of the N string operator ?
> 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

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

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Danilo Fortunato  writes:
> 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

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

От:
Danilo Fortunato <danilo.fortunato.2@gmail.com>
Дата:
Thanks a lot for your support.

Danilo


FAQ