Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rNELC-00AH9Y-5r for pgsql-general@arkaria.postgresql.org; Tue, 09 Jan 2024 15:48:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rNELB-00Drxj-Bi for pgsql-general@arkaria.postgresql.org; Tue, 09 Jan 2024 15:48:33 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rNELB-00Drxb-15 for pgsql-general@lists.postgresql.org; Tue, 09 Jan 2024 15:48:33 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rNEL8-000g42-Mt for pgsql-general@lists.postgresql.org; Tue, 09 Jan 2024 15:48:31 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 409FmS4A2186785; Tue, 9 Jan 2024 10:48:28 -0500 From: Tom Lane To: Laurenz Albe cc: Kiran K V , pgsql-general@lists.postgresql.org Subject: Re: ERROR: invalid byte sequence for encoding UTF8: 0x00 In-reply-to: <2f91c83c9529ad677091b3c167292eb5967bbb6e.camel@cybertec.at> References: <2f91c83c9529ad677091b3c167292eb5967bbb6e.camel@cybertec.at> Comments: In-reply-to Laurenz Albe message dated "Tue, 09 Jan 2024 16:13:28 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2186783.1704815308.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 09 Jan 2024 10:48:28 -0500 Message-ID: <2186784.1704815308@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Laurenz Albe 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 v= alues ? > This is not about loading data into a "bytea", but into a "text", "varch= ar" 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