| From: | Hoda Salim <hoda(dot)s(dot)salim(at)gmail(dot)com> |
|---|---|
| To: | Erik Wienhold <ewie(at)ewie(dot)name> |
| Cc: | pgsql-docs(at)lists(dot)postgresql(dot)org |
| Subject: | Re: [PATCH] docs: document N'...' national character string literal syntax |
| Date: | 2026-02-02 20:04:12 |
| Message-ID: | CAAGT0i+SrExi4LVf-gQ4t9XY724pVRxEvOZft4B0uUs-gDuYHA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-docs |
> nchar is an alias of bpchar. There's no cast to char behind the scenes
> since that would truncate the string:
>
> select n'foo', 'foo'::character;
> bpchar | bpchar
> --------+--------
> foo | f
> (1 row)
Thank you for catching this! I verified the behavior and updated the
documentation to correctly state that N'...' is equivalent to a bpchar
literal.
> Should we also mention the nchar alias in [4]?
> [4] https://www.postgresql.org/docs/current/datatype-character.html
I'm happy to add that in a v3 if you think it belongs in this patch.
I wasn't sure if it would be preferred separately or together.
Updated patch attached.
--
Hoda Salim
On Mon, Feb 2, 2026 at 7:09 PM Erik Wienhold <ewie(at)ewie(dot)name> wrote:
>
> On 2026-02-02 16:05 +0100, Hoda Salim wrote:
> > This patch documents the N'...' national character string literal
> > syntax, which has been supported by PostgreSQL but was previously
> > undocumented.
> >
> > The documentation explains:
> > - What the syntax is (N'hello')
> > - What the SQL standard specifies (implementation-defined national
> > character set)
> > - What PostgreSQL actually does (treats it as a cast to character type)
> > - Why it exists (compatibility with SQL migrated from other databases)
> >
> > I verified the documentation builds without errors.
>
> +1
>
> I brought up the missing documentation before [1], but wasn't sure at
> the time if Postgres conforms to the SQL standard (mainly because of
> [2]). Now I see that [3] already claims to support national character
> (F421). That entry was commented with "syntax accepted" until commit
> 35223af0579. I read that as "fully supported" now.
>
> > + <productname>PostgreSQL</productname> does not implement a separate
> > + national character set; it treats <literal>N'...'</literal> as
> > + equivalent to a regular string constant cast to the
> > + <type>character</type> type, that is, <literal>'...'::character</literal>,
> > + using the database's character set.
>
> nchar is an alias of bpchar. There's no cast to char behind the scenes
> since that would truncate the string:
>
> select n'foo', 'foo'::character;
> bpchar | bpchar
> --------+--------
> foo | f
> (1 row)
>
> Should we also mention the nchar alias in [4]?
>
> [1] https://www.postgresql.org/message-id/om3g7p7u3ztlrdp4tfswgulavljgn2fe6u2agk34mrr65dffuu%40cpzlzuv6flko
> [2] https://www.postgresql.org/message-id/1275895438.1849.1.camel@fsopti579.F-Secure.com
> [3] https://www.postgresql.org/docs/current/features-sql-standard.html
> [4] https://www.postgresql.org/docs/current/datatype-character.html
>
> --
> Erik Wienhold
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-docs-document-N-.-national-character-string-liter.patch | application/octet-stream | 2.9 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Erik Wienhold | 2026-02-04 00:24:34 | Re: [PATCH] docs: document N'...' national character string literal syntax |
| Previous Message | Erik Wienhold | 2026-02-02 17:09:18 | Re: [PATCH] docs: document N'...' national character string literal syntax |