pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #14251: COPY CSV: missing data for column that shouldn't be
3+ messages / 3 participants
[nested] [flat]

* BUG #14251: COPY CSV: missing data for column that shouldn't be
@ 2016-07-15 02:03 mickael.kerjean@gmail.com
  2016-07-15 06:12 ` Re: BUG #14251: COPY CSV: missing data for column that shouldn't be John R Pierce <pierce@hogranch.com>
  2016-07-15 09:08 ` Re: BUG #14251: COPY CSV: missing data for column that shouldn't be Francisco Olarte <folarte@peoplecall.com>
  0 siblings, 2 replies; 3+ messages in thread

From: mickael.kerjean@gmail.com @ 2016-07-15 02:03 UTC (permalink / raw)
  To: pgsql-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


^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #14251: COPY CSV: missing data for column that shouldn't be
  2016-07-15 02:03 BUG #14251: COPY CSV: missing data for column that shouldn't be mickael.kerjean@gmail.com
@ 2016-07-15 06:12 ` John R Pierce <pierce@hogranch.com>
  1 sibling, 0 replies; 3+ messages in thread

From: John R Pierce @ 2016-07-15 06:12 UTC (permalink / raw)
  To: pgsql-bugs

On 7/14/2016 7:03 PM, mickael.kerjean@gmail.com wrote:
> "af,dekh"iykh'ya,Dekh"iykh'ya,13,,34.60345,69.2405"
> => The csv is valid but postgres doesn't really get it right

the quotes don't make much sense at all.

     country_code = "af
     city = dekh"iykh'ya
     city_accent = Dekh"iykh'ya
     region = 13
     population = NULL
     lat = 34.60345
     lng = 69.2405"



is dekh"iykh'ya  supposed to be accented characters or something?  If 
you don't specify a QUOTE on your COPY command, it defaults to ", this 
will definitely mess things up.   you might try specifying a QUOTE '%' 
or something that doesn't exist in your data, I don't think you can 
disable QUOTE entirely on CSV format copies.

-- 
john r pierce, recycling bits in santa cruz



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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #14251: COPY CSV: missing data for column that shouldn't be
  2016-07-15 02:03 BUG #14251: COPY CSV: missing data for column that shouldn't be mickael.kerjean@gmail.com
@ 2016-07-15 09:08 ` Francisco Olarte <folarte@peoplecall.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Francisco Olarte @ 2016-07-15 09:08 UTC (permalink / raw)
  To: mickael.kerjean@gmail.com; +Cc: pgsql-bugs

Mickael:

On Fri, Jul 15, 2016 at 4:03 AM,  <mickael.kerjean@gmail.com> wrote:

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

I've downloaded it, it is NOT in CSV format, CSV means more than commas.

I've checked it does not need scaping by doing:

$ perl -ne '@x=split/,/,$_; 7==@x or print "$.-$_";'
~/Downloads/worldcitiespop.txt | head

And not getting any output, and checked it does not have backslashes by doing

$ fgrep -c '\' ~/Downloads/worldcitiespop.txt
0

So you could probably load it by NOT using CSV ( as the .txt extension
hints ), that is use FORMAT text ( the default ) and DELIMITER ',' and
it will probably get in fine ( try some variations if not ).

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

Excel lies. A lot. Maybe with good intention, but it does many things
behind the scenes, like parsing non-csv data right when told to read
CSV.

Also, CSV is a very ill defined format, I've been unable to use it
properly since the Multiplan days, specially since they started
putting L10N/I18N in it.

Francisco Olarte.


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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2016-07-15 09:08 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-07-15 02:03 BUG #14251: COPY CSV: missing data for column that shouldn't be mickael.kerjean@gmail.com
2016-07-15 06:12 ` John R Pierce <pierce@hogranch.com>
2016-07-15 09:08 ` Francisco Olarte <folarte@peoplecall.com>

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