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 1lyrJA-0005DM-Uj for pgsql-admin@arkaria.postgresql.org; Thu, 01 Jul 2021 07:40:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lyrJ9-0007tN-Ud for pgsql-admin@arkaria.postgresql.org; Thu, 01 Jul 2021 07:40:23 +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 1lyrJ9-0007tF-Lp for pgsql-admin@lists.postgresql.org; Thu, 01 Jul 2021 07:40:23 +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 1lyrJ7-0004dC-Fu for pgsql-admin@lists.postgresql.org; Thu, 01 Jul 2021 07:40:23 +0000 Received: from localhost (localhost [127.0.0.1]) by rs.plausibolo.de (Postfix) with ESMTP id 2EBF538048A; Thu, 1 Jul 2021 09:40:20 +0200 (CEST) Received: from rs.plausibolo.de ([IPv6:::1]) by localhost (h2367442.stratoserver.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id xw7ZQigX_k-0; Thu, 1 Jul 2021 09:40:20 +0200 (CEST) Received: from tuxedo.local.de (p5b248469.dip0.t-ipconnect.de [91.36.132.105]) by rs.plausibolo.de (Postfix) with ESMTPSA id E945638045E; Thu, 1 Jul 2021 09:40:19 +0200 (CEST) Subject: Re: Invalid byte sequence To: pgsql-admin@lists.postgresql.org References: From: Holger Jakobs Message-ID: Date: Thu, 1 Jul 2021 09:40:19 +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="2bxOQBlcemz7W754T8EMEVGXlW0kx2XK9" 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) --2bxOQBlcemz7W754T8EMEVGXlW0kx2XK9 Content-Type: multipart/mixed; boundary="01pUahy1GHeViqukaHnLcaUFBpqnoKNGy"; protected-headers="v1" From: Holger Jakobs To: pgsql-admin@lists.postgresql.org Message-ID: Subject: Re: Invalid byte sequence References: In-Reply-To: --01pUahy1GHeViqukaHnLcaUFBpqnoKNGy Content-Type: multipart/alternative; boundary="------------2342E20D4BC2167B75F659B7" Content-Language: de-DE This is a multi-part message in MIME format. --------------2342E20D4BC2167B75F659B7 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable 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=20 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?=20 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 table = > which points to a csv file and when i try to create another table it=20 > 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 "UTF8": 0x00 > CONTEXT: =C2=A0COPY table1, line 377617 --=20 Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012 --------------2342E20D4BC2167B75F659B7 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

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:

'$ d' /outputfile.csv<=
/pre>
    

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 for= eign 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 "UTF8": 0x00=
CONTEXT: =C2=A0COPY table1, line 377617
--=20
Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012
--------------2342E20D4BC2167B75F659B7-- --01pUahy1GHeViqukaHnLcaUFBpqnoKNGy-- --2bxOQBlcemz7W754T8EMEVGXlW0kx2XK9 Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wmMEABEIACMWIQScuJCxWJK1p5BOebGKV5yTsxlhugUCYN1xYwUDAAAAAAAKCRCKV5yTsxlhusiX AKCyoEnK1iGptVQJOsO6IoqKx7bjTQCfd8vyedhfbcoaUEN4v19iLBz2xHk= =S93a -----END PGP SIGNATURE----- --2bxOQBlcemz7W754T8EMEVGXlW0kx2XK9--