Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jHx00-0007wm-5t for pgsql-general@arkaria.postgresql.org; Fri, 27 Mar 2020 21:58:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jHwzy-0002g6-VY for pgsql-general@arkaria.postgresql.org; Fri, 27 Mar 2020 21:58:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jHwzy-0002fz-MA for pgsql-general@lists.postgresql.org; Fri, 27 Mar 2020 21:58:42 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jHwzt-0000Is-Ku for pgsql-general@lists.postgresql.org; Fri, 27 Mar 2020 21:58:40 +0000 Received: from [192.168.127.1] (port=42851 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtp (Exim 4.92.3 (FreeBSD)) (envelope-from ) id 1jHwzo-000F6C-K2; Fri, 27 Mar 2020 21:58:32 +0000 Received: from localhost ([127.0.0.1]:21168 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.92.3 (FreeBSD)) (envelope-from ) id 1jHwzo-0008er-Eh; Fri, 27 Mar 2020 21:58:32 +0000 From: Andrew Gierth To: Thomas Munro Cc: Tom Lane , Matthias Apitz , "pgsql-generallists.postgresql.org" Subject: Re: \COPY to accept non UTF-8 chars in CHAR columns In-Reply-To: (Thomas Munro's message of "Sat, 28 Mar 2020 09:40:30 +1300") Message-ID: <87k135a2hd.fsf@news-spur.riddles.org.uk> References: <20200327153623.GA32266@sh4-5.1blu.de> <8922.1585323994@sss.pgh.pa.us> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (berkeley-unix) Date: Fri, 27 Mar 2020 21:58:32 +0000 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Thomas" == Thomas Munro writes: Thomas> Something like this approach might be useful for fixing the CSV file: Thomas> https://codereview.stackexchange.com/questions/185821/convert-a-mix-of-latin-1-and-utf-8-to-proper-utf-8 Or: perl -MEncode -pe ' use bytes; sub c { decode("UTF-8",shift,sub { decode("windows-1252", chr(shift)) }); } s/([\x80-\xFF]+)/encode("UTF-8",c($1))/eg' outfile -- Andrew (irc:RhodiumToad)