Re: Invalid Unicode escape value at or near "\u0000"

From: Japin Li <japinli(at)hotmail(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Invalid Unicode escape value at or near "\u0000"
Date: 2021-11-13 14:23:31
Message-ID: MEYP282MB1669997A0DAB285D2B1CF50BB6969@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On Sat, 13 Nov 2021 at 21:52, Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:
> On 11/13/21 00:40, Thomas Munro wrote:
>> On Sat, Nov 13, 2021 at 4:32 PM Japin Li <japinli(at)hotmail(dot)com> wrote:
>>> When I try to insert an Unicode "\u0000", there is an error $subject.
>>>
>>> postgres=# CREATE TABLE tbl (s varchar(10));
>>> CREATE TABLE
>>> postgres=# INSERT INTO tbl VALUES (E'\u0000');
>>> ERROR: invalid Unicode escape value at or near "\u0000"
>>> LINE 1: INSERT INTO tbl VALUES (E'\u0000');
>>> ^
>>>
>>> "\u0000" is valid unicode [1], why not we cannot insert it?
>> Yes, it is a valid codepoint, but unfortunately PostgreSQL can't
>> support it because it sometimes deals in null terminated string, even
>> though internally it does track string data and length separately. We
>> have to do that to use libc facilities like strcoll_r(), and probably
>> many other things.
>>
>>
>
> And it's documented at
> <https://www.postgresql.org/docs/current/datatype-character.html>:
>
>
> The characters that can be stored in any of these data types are
> determined by the database character set, which is selected when the
> database is created. Regardless of the specific character set, the
> character with code zero (sometimes called NUL) cannot be stored.
>
>

Thanks Thomas and Andrew. Sorry for my ignore reading of the documentation.

--
Regrads,
Japin Li.
ChengDu WenWu Information Technology Co.,Ltd.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bharath Rupireddy 2021-11-13 14:27:54 Re: Logical Replication - improve error message while adding tables to the publication in check_publication_add_relation
Previous Message Bharath Rupireddy 2021-11-13 13:59:36 Re: add recovery, backup, archive, streaming etc. activity messages to server logs along with ps display