What is the meaning of the N string operator ?

Started by Danilo Fortunatoalmost 11 years ago4 messagesdocs
Jump to latest
#1Danilo 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

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

#2Andreas Seltenreich
seltenreich@gmx.de
In reply to: Danilo Fortunato (#1)
Re: What is the meaning of the N string operator ?

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

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

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Danilo Fortunato (#1)
Re: What is the meaning of the N string operator ?

Danilo Fortunato <danilo.fortunato.2@gmail.com> 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

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

#4Danilo Fortunato
danilo.fortunato.2@gmail.com
In reply to: Danilo Fortunato (#1)
Re: What is the meaning of the N string operator ?

Thanks a lot for your support.

Danilo

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