Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lyrSD-0005Xo-NF for pgsql-admin@arkaria.postgresql.org; Thu, 01 Jul 2021 07:49:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lyrSC-0008EZ-Dq for pgsql-admin@arkaria.postgresql.org; Thu, 01 Jul 2021 07:49:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lyrSC-0008ER-3h for pgsql-admin@lists.postgresql.org; Thu, 01 Jul 2021 07:49:44 +0000 Received: from jakobs.com ([85.214.83.89] helo=rs.plausibolo.de) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lyrS6-0004ip-1n for pgsql-admin@lists.postgresql.org; Thu, 01 Jul 2021 07:49:43 +0000 Received: from localhost (localhost [127.0.0.1]) by rs.plausibolo.de (Postfix) with ESMTP id 6D74038040F; Thu, 1 Jul 2021 09:49:37 +0200 (CEST) Received: from rs.plausibolo.de ([IPv6:::1]) by localhost (h2367442.stratoserver.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id woMWVEXmusK8; Thu, 1 Jul 2021 09:49:37 +0200 (CEST) Received: from tuxedo.local.de (p5b248469.dip0.t-ipconnect.de [91.36.132.105]) by rs.plausibolo.de (Postfix) with ESMTPSA id 2FAFD3801EC; Thu, 1 Jul 2021 09:49:37 +0200 (CEST) Subject: Re: Invalid byte sequence To: pgsql-admin@lists.postgresql.org References: From: Holger Jakobs Message-ID: <782159a8-4a60-dc25-2907-67e21f4acf99@jakobs.com> Date: Thu, 1 Jul 2021 09:49:36 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="eomtPfR97nd6k4RdeORt62A0KHQyFBQ56" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --eomtPfR97nd6k4RdeORt62A0KHQyFBQ56 Content-Type: multipart/mixed; boundary="5KyopWFyCJz8NFeeDxqZI2ZVCkyv7OCYn"; protected-headers="v1" From: Holger Jakobs To: pgsql-admin@lists.postgresql.org Message-ID: <782159a8-4a60-dc25-2907-67e21f4acf99@jakobs.com> Subject: Re: Invalid byte sequence References: In-Reply-To: --5KyopWFyCJz8NFeeDxqZI2ZVCkyv7OCYn Content-Type: multipart/alternative; boundary="------------BBC89DE983E7B2DE4176A79D" Content-Language: de-DE This is a multi-part message in MIME format. --------------BBC89DE983E7B2DE4176A79D Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Then have a look at the line 377617 and check whether its content is=20 important. The following command shows the line on the terminal. Loading = it into an interactive editor seems not to be an option due to the size=20 of the file |sed -n '||377617 p;|||||377617| q' |/outputfile.csv Then you can decide what to do. Am 01.07.21 um 09:45 schrieb Yambu: > Hi=C2=A0Holger > > There are 8mil lines, the file is not in /=C2=A0 , i just removed the o= ther=20 > parts. > > On Thu, Jul 1, 2021 at 9:40 AM Holger Jakobs > wrote: > > How many lines has the file? Maybe line 377617 is the last one. > > If so, you can just remove the last line containing this 0x00. The > following command can do this for you: > > |sed -i '$ d' |/outputfile.csv > > May I remark that having a file in the / directory is a bit > awkward? This directory should not be writable by any user (except > root, and root doesn't fiddle with files for a database). > > > > Am 01.07.21 um 09:29 schrieb Yambu: >> Hello >> >> How do i get past the error below.=C2=A0I have created a foreign t= able >> which points to a csv file and when i try to create another table >> it gives error below >> >> The csv file has funny characters, how do i bypass those character= s. >> >> create foreign table table1 >> ( >> id int, >> name text >> ) >> SERVER local_file >> OPTIONS (filename '/outputfile.csv' , >> format 'csv', >> header 'TRUE', >> delimiter ';' >> ); >> >> >> create table2 as select * from=C2=A0table1; >> >> ERROR: =C2=A0invalid byte sequence for encoding "UTF8": 0x00 >> CONTEXT: =C2=A0COPY table1, line 377617 > > --=20 > Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012 > --=20 Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012 --------------BBC89DE983E7B2DE4176A79D Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

Then have a look at the line 377617 and check whether its content is important. The following command shows the line on the terminal. Loading it into an interactive editor seems not to be an option due to the size of the file

sed -n '377617 p; 377617 q' /outputfile.csv
Then you can decide what to do.

Am 01.07.21 um 09:45 schrieb Yambu:
Hi=C2=A0Holger

There are 8mil lines, the file is not in /=C2=A0 , i just removed the other parts.

On Thu, Jul 1, 2021 at 9:40= AM Holger Jakobs <holger@jakobs.com> wrote:
=
=

How many lines has the file? Maybe line 377617 is the last one.

If so, you can just remove the last line containing this 0x00. The following command can do this for you:

sed -i '$ d' /outputfile.csv
            

May I remark that having a file in the / directory is a bit awkward? This directory should not be writable by any user (except root, and root doesn't fiddle with files for a database).



Am 01.07.21 um 09:29 schrieb Yambu:
Hello

How do i get past the error below.=C2=A0I have creat= ed a foreign table which points to a csv file and when i try to create another table it gives error below

The csv file has funny characters, how do i bypass those characters.

create foreign table table1
(
id int,
name text
)
SERVER local_file
OPTIONS (filename '/outputfile.csv' ,
format 'csv',
header 'TRUE',
delimiter ';'
);


create table2 as select * from=C2=A0table1;

ERROR: =C2=A0invalid byte sequence for encoding "UTF= 8": 0x00
CONTEXT: =C2=A0COPY table1, line 377617
--=20
Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012
--=20
Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012
--------------BBC89DE983E7B2DE4176A79D-- --5KyopWFyCJz8NFeeDxqZI2ZVCkyv7OCYn-- --eomtPfR97nd6k4RdeORt62A0KHQyFBQ56 Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wmMEABEIACMWIQScuJCxWJK1p5BOebGKV5yTsxlhugUCYN1zkAUDAAAAAAAKCRCKV5yTsxlhumIz AKCGaWIKZUri4/s4dwqVZcrtGJ1XhQCg2gsLr2bIfEGjdJLAM9C4GlEdek0= =Iimr -----END PGP SIGNATURE----- --eomtPfR97nd6k4RdeORt62A0KHQyFBQ56--