pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: mickael.kerjean@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #14251: COPY CSV: missing data for column that shouldn't be
Date: Fri, 15 Jul 2016 02:03:34 +0000
Message-ID: <20160715020334.1425.78931@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

The following bug has been logged on the website:

Bug reference:      14251
Logged by:          Mickael Kerjean
Email address:      mickael.kerjean@gmail.com
PostgreSQL version: 9.5.0
Operating system:   Ubuntu 16.04
Description:        

Hello,

First of all, thank you for making such a cool database.

I'm having some bad time inserting data in a csv format coming from:
https://www.maxmind.com/en/free-world-cities-database

The data itself contains cities from all around the world.

- My Schema is:
CREATE TABLE cities(
    country_code VARCHAR(2),
    city VARCHAR(256),
    city_accent VARCHAR(256),
    region VARCHAR(128),
    population FLOAT DEFAULT NULL,
    lat FLOAT,
    lng FLOAT
)
- Regarding the encoding at the file:
mickael@ubuntu:~$ file -i worldcitiespop.csv
worldcitiespop.csv: text/plain; charset=iso-8859-1
- the query is rather simple:
COPY cities FROM '/home/mickael/worldcitiespop.csv' DELIMITER ',' CSV HEADER
ENCODING 'iso-8859-1';
- The error I'm getting: 
ERROR:  missing data for column "lng"
CONTEXT:  COPY cities, line 19970:
"af,dekh"iykh'ya,Dekh"iykh'ya,13,,34.60345,69.2405"
=> The csv is valid but postgres doesn't really get it right

I tried a few things:
1) convert the file to utf8 using the following command:
iconv -f ISO-8859-1 -t UTF-8 worldcitiespop.csv > worldcitiespop_utf8.csv
2) get rid of the header
3) try to reimport the data:
COPY cities FROM '/home/mickael/worldcitiespop_utf8.csv' DELIMITER ','
CSV;

Same results. 
Looking at the error, it might not be impossible postgres is thinking the "
characters are part of 1 string -> ->
https://github.com/postgres/postgres/blob/562e44972490196884452e632a0a6d0db81b2335/src/bin/psql/tab-...

I tried to import this file using excel and everything was working as
expected





-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


view thread (3+ messages)  latest in thread

Message-ID: <20160715020334.1425.78931@wrigleys.postgresql.org>
Permalink:  ../20160715020334.1425.78931@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20160715020334.1425.78931@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: mickael.kerjean@gmail.com
  Subject: Re: BUG #14251: COPY CSV: missing data for column that shouldn't be
  In-Reply-To: <20160715020334.1425.78931@wrigleys.postgresql.org>
  References: <20160715020334.1425.78931@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox