Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 84BFC650739 for ; Thu, 10 Jul 2008 23:02:19 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 95525-01 for ; Thu, 10 Jul 2008 23:02:09 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from yw-out-2324.google.com (yw-out-2324.google.com [74.125.46.29]) by postgresql.org (Postfix) with ESMTP id 9A10F650727 for ; Thu, 10 Jul 2008 23:02:15 -0300 (ADT) Received: by yw-out-2324.google.com with SMTP id 3so1649253ywj.73 for ; Thu, 10 Jul 2008 19:02:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type:content-transfer-encoding :content-disposition; bh=S0nIWc90F6l8ICDMtVIP4bfYEygPI1Z+PsSa9hxiwiY=; b=IgOubaVen3/KzTPEYXY/x5VskobE2f1h9lBIZzVaN8K7HWbpMyXxxssZC+tGBJCFEG 6Pph6g8kmrYlmymdbs5AEkIlnPiJQO2GPLHMCpzLcOIKOeeMBzut8aFHnNgWuNDiJ2n0 W3DwxFNps3ARyGIepGm0143UjldovK1krqcWc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type :content-transfer-encoding:content-disposition; b=wbQFC1fLuENEHYJShzuZq9Rqy0PYvS9AYOvTBX4I4HKCDP2lMcZTu4Xl7fHMcF0DSu K4wtNNizJoTG3MYnNuVPuUBIT0kj05YlMnzEEXZR31fCohtp7fQqobjQ9sothGsfGCb8 hE87fLpcON7IpaJKpRHY5+Lf5xVMgf8Dp0Z4U= Received: by 10.142.132.2 with SMTP id f2mr2854353wfd.256.1215741721166; Thu, 10 Jul 2008 19:02:01 -0700 (PDT) Received: by 10.142.222.13 with HTTP; Thu, 10 Jul 2008 19:02:01 -0700 (PDT) Message-ID: <57a815bf0807101902o193644ear50e211e67663d874@mail.gmail.com> Date: Fri, 11 Jul 2008 12:02:01 +1000 From: "Mikel Lindsaar" To: pgsql-admin@postgresql.org Subject: Importing data - possible UTF8 import bug? MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200807/107 X-Sequence-Number: 29717 Hi all, I am importing a bunch of data exported from an Oracle database. This came out as a flat file, tab delimited. I have parsed this through a ruby script that does the following: For each line split it at the tab for each column parse it through Iconv and convert from UTF8 to UTF8 on failure dump the line into a log for inspection and continue check to see if the column value ends in a single \ if so, add another \ to escape it and not the tab that will follow check to see if the column value is blank if so, replace with \N join the array back together with tabs write it out to the import file. This works quite well. The ruby script handles about 10,000 lines every 15 seconds or so. Theoretically no invalid utf-8 sequences could end up in the output file as everything is passed through Iconv and if it raises an except it dumps the offending line into a separate file for manual handling. But I am hitting a problem. When I try to import the result with COPY I am getting: ERROR: invalid byte sequence for encoding "UTF8": 0xa2 And gives me a line reference. I then grabbed that line out of the file, unpacked each byte into a decimal representation and 162 does not appear anywhere. Additionally I did: Iconv.iconv('UTF-8', 'UTF-8', line).join == line Which takes the line and converts it from UTF8 to UTF8 using the Iconv library (--f UTF-8 -t UTF-8) and this returns true. Interestingly, the following also returns true: Iconv.iconv('ASCII', 'UTF-8', line).join == line #=> true So there can't be any non ASCII characters in there. Unpacking the line and uniq'ing it and sorting it gives the following: @result.unpack('U'*@result.length).uniq.sort => [9, 10, 32, 45, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 65, 66, 67, 68, 69, 70, 72, 73, 74, 76, 77, 78, 79, 80, 82, 83, 84, 85, 87, 91, 92, 93, 97, 98, 99, 101, 109, 110, 111, 114, 116, 117, 121] Anyone got any ideas how I can hunt down what is in this row, visually looking at it hasn't helped? Mikel -- http://lindsaar.net/ Rails, RSpec and Life blog....