From aecb9e6fdacb92cc96099afd89ad0a628b97e916 Mon Sep 17 00:00:00 2001 From: HodaSalim Date: Mon, 2 Feb 2026 14:54:37 +0000 Subject: [PATCH] docs: document N'...' national character string literal syntax Document the N'...' string literal syntax in the Lexical Structure section of the documentation. This SQL-standard syntax for national character string literals has been supported by PostgreSQL but was previously undocumented. The documentation explains that while the SQL standard specifies this syntax for an implementation-defined national character set, PostgreSQL treats N'...' as equivalent to a cast to the character type using the database's encoding, since PostgreSQL uses a single character set for all string types. --- doc/src/sgml/syntax.sgml | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/doc/src/sgml/syntax.sgml b/doc/src/sgml/syntax.sgml index 67482996861..85e1f9c436f 100644 --- a/doc/src/sgml/syntax.sgml +++ b/doc/src/sgml/syntax.sgml @@ -590,6 +590,49 @@ $function$ + + National Character String Constants + + + national character + string constant + + + + PostgreSQL accepts string constants + with a leading N (upper or lower case) + immediately before the opening single quote, for + example N'hello'. This syntax is specified by + the SQL standard for identifying string + literals of national character types + (NCHAR and NCHAR VARYING). + + + + The SQL standard specifies that strings written + with this syntax should use an implementation-defined + national character set. + PostgreSQL does not implement a separate + national character set; it treats N'...' as + equivalent to a regular string constant cast to the + character type, that is, '...'::character, + using the database's character set. + Since character without a length specifier accepts strings + of any size, the result is a value of type character + with the length of the given string. Note that trailing spaces + are semantically insignificant in character values. + + + + This syntax is accepted primarily for compatibility with SQL + migrated from other database systems. Since + PostgreSQL uses a single character set + for all string types (determined by the database encoding), + there is typically no advantage to using + N'...' over regular string constants. + + + Bit-String Constants -- 2.43.0