ERROR: invalid byte sequence for encoding UTF8: 0x00

Started by Kiran K Vover 2 years ago3 messagesgeneral
Jump to latest
#1Kiran K V
kirankv.1982@gmail.com

Hi,

I have a table with bytea column and trying to load the data using copy
command. But Copy command is failing with "ERROR: invalid byte sequence
for encoding UTF8: 0x00. Why postgresql is failing to load when data
contains 0x00. How to resolve this error ? any workaround to load the data
with 0x00 values ?

Please advise. Thank you very much.

Regards,
Kiran

#2Laurenz Albe
laurenz.albe@cybertec.at
In reply to: Kiran K V (#1)
Re: ERROR: invalid byte sequence for encoding UTF8: 0x00

On Tue, 2024-01-09 at 17:48 +0530, Kiran K V wrote:

I have a table with bytea column and trying to load the data using copy command.
But Copy command is failing with
"ERROR: invalid byte sequence for encoding UTF8: 0x00.
Why postgresql is failing to load when data contains 0x00.
How to resolve this error ? any workaround to load the data with 0x00 values ?

This is not about loading data into a "bytea", but into a "text", "varchar" or
"char" column. Check again.

Yours,
Laurenz Albe

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Laurenz Albe (#2)
Re: ERROR: invalid byte sequence for encoding UTF8: 0x00

Laurenz Albe <laurenz.albe@cybertec.at> writes:

On Tue, 2024-01-09 at 17:48 +0530, Kiran K V wrote:

I have a table with bytea column and trying to load the data using copy command.
But Copy command is failing with
"ERROR: invalid byte sequence for encoding UTF8: 0x00.
Why postgresql is failing to load when data contains 0x00.
How to resolve this error ? any workaround to load the data with 0x00 values ?

This is not about loading data into a "bytea", but into a "text", "varchar" or
"char" column. Check again.

I am guessing that the OP tried to put a literal NUL character
into the COPY data. A bytea value in COPY data needs to be
text-encoded as per one of the alternatives explained in the
manual. Alternatively, you could jump through the hoops involved
in sending binary COPY data.

regards, tom lane