lorint / AdventureWorks-for-Postgres

Set up the AdventureWorks sample database for use with Postgres
MIT License
369 stars 185 forks source link

Empty rows in several CSV files prevent COPY #1

Closed ElRico closed 7 years ago

ElRico commented 8 years ago

First of all thanks for creating this project!

I just ran the ruby and sql scripts, but found that the SQL script threw errors on the COPY commands of the following CSV files:

StateProvince CountryRegion Employee ProductDescription CountryRegionCurrency

Subsequent commands in the script will fail as well, since foreign keys were being violated.

The solution for me was to remove the empty rows in these CSV files and then the script ran through without an issue.

lorint commented 7 years ago

Hi @ElRico! Glad you're finding value from these scripts. To confess, I haven't touched them in awhile and just now saw your note, hence the late response.

What platform are you running on? I can't replicate the issue you're seeing on Ubuntu or OSX. I kind of suspect that a few lines are terminated with \r\n and most others with just \r or \n alone; a platform-dependent kind of thing.

ElRico commented 7 years ago

Hi @lorint, I was running the scripts on Windows 10.

lorint commented 7 years ago

Found a Windows 8 machine that I could check this out with and reproduced the issue you found. Ended up that the fix was with how Windows machines do newline -- \r\n vs just \n. Everything should be working with this commit:

7a3eb65048040e2d960f40c8975e9809264564c5

Note that when SELECTing rows with unicode characters that you must first set the client_encoding to UTF8:

SET CLIENT_ENCODING=UTF8;
SELECT * FROM pr.pd WHERE id=1371;

(pd is a convenience view in the pr schema, and refers to production.productdescription.)

Enjoy!