Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id B16279FC872 for ; Thu, 25 Oct 2007 13:16:32 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 75629-02 for ; Thu, 25 Oct 2007 13:16:27 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from k2smtpout06-02.prod.mesa1.secureserver.net (k2smtpout06-02.prod.mesa1.secureserver.net [64.202.189.103]) by postgresql.org (Postfix) with SMTP id 89E2C9FC55D for ; Thu, 25 Oct 2007 13:16:15 -0300 (ADT) Received: (qmail 5883 invoked from network); 25 Oct 2007 16:16:13 -0000 Received: from unknown (HELO mail.servantwebhosting.com) (68.178.159.82) by k2smtpout06-02.prod.mesa1.secureserver.net (64.202.189.103) with ESMTP; 25 Oct 2007 16:16:12 -0000 Received: (qmail 22513 invoked from network); 25 Oct 2007 09:16:10 -0700 Received: from s010600e0296eec95.mj.shawcable.net (HELO shach) (rob@nullmx.com@70.64.195.140) by mail.servantwebhosting.com with SMTP; 25 Oct 2007 09:16:10 -0700 From: "Chuck D." Reply-To: pgsql-list@nullmx.com To: pgsql-sql@postgresql.org Subject: Re: request for help with COPY syntax Date: Thu, 25 Oct 2007 10:16:01 -0600 User-Agent: KMail/1.9.6 References: <200710231019.07833.pgsql-list@nullmx.com> <471EF003.7030707@autoledgers.com.au> <200710250935.24041.pgsql-list@nullmx.com> In-Reply-To: <200710250935.24041.pgsql-list@nullmx.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200710251016.01844.pgsql-list@nullmx.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/118 X-Sequence-Number: 29490 On October 25, 2007 09:35:23 am Chuck D. wrote: > On October 24, 2007 01:10:59 am Paul Lambert wrote: > > I get around this problem with my data loads by specifying some other > > arbitrary character that I know won't appear in the data as the quote > > character. > > > > Eg QUOTE E'\f' will specify form feed as the quote character, ergo any > > data with double or single quotes will be loaded with those quote > > characters in the string. > > > > Something similar may help with your case. > > This was the solution. I specified a quote character that was not in the > data and the data imported perfectly. Without specifying any delimiter > postgres defaults to one of the quotes (I forget which). > > Unfortunately, the data I imported wasn't good. MaxMind, like the > Geonames.org derivatives, uses FIPS code for a state identifier in the > cities table for all countries EXCEPT USA in which case they use the iso > code. Both these data sets mix types within one column and I find that > absolutely unacceptable. > > Back to my original problem, which was trying to COPY in some of the > earth-info.nga.mil world city data. This data is tab delimited, no quotes > around fields, newline line terminated and UTF-8 encoded. > > Using a similar COPY statement with the defaults, it fails with this: > > COPY geo.orig_city FROM > '/home/www/geo/DATA/nga.mil/geonames_no_header.txt'; > > ERROR: literal carriage return found in data > HINT: Use "\r" to represent carriage return. > CONTEXT: COPY orig_city, line 1071850 > > And of course, at that line we find a field that has several lines which > appear (using cat -A) to be terminated with a new line ($). I originally > deleted this line but there are others like it. And the file is 2 Gigs in > size so it isn't acceptable to comb through it. > > I believe this is a new problem because I have a vintage file dated early > 2007 that didn't have this problem. Does anyone know how to solve this > COPY issue? > Pardon me on this, the cat -A report for the failed line (and subsequent lines) shows ^M$ within the field, not just $. I assume that is probably a \r\n and postgres wants \r for field data and \n to end a line. I've tried working this over with sed but can't get the syntax right. I also have iconv installed if that would help any. Are there any good tools that will tell me what this really is instead of just ^M$ ?