Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR: could not stat file "XX.csv": Unknown error

Tags:

I run this command:

COPY XXX FROM 'D:/XXX.csv'  WITH (FORMAT CSV, HEADER TRUE, NULL 'NULL') 

In Windows 7, it successfully imports CSV files of less than 1GB.

If the file is more then 1GB big, I get an “unknown error”.

[Code: 0, SQL State: XX000]  ERROR: could not stat file "'D:/XXX.csv'  Unknown error 

How can I fix this issue?

like image 939
亚军吴 Avatar asked Nov 28 '18 15:11

亚军吴


Video Answer


2 Answers

You can work around this by piping the file through a program. For example I just used this to copy from a 24GB file on Windows 10 and PostgreSQL 11.

copy t(c,d) from program 'cmd /c "type x:\path\to\file.txt"' with (format text); 

This copies the text file file.txt into the table t, columns c and d.

The trick here is to run cmd in a single command mode, with /c and telling it to type out the file in question.

like image 171
Johann Oskarsson Avatar answered Sep 22 '22 07:09

Johann Oskarsson


https://github.com/MIT-LCP/mimic-code/issues/493 alistairewj commented Nov 3, 2018 • ► edited

Okay, the could not stat file "CHARTEVENTS.csv": Unknown error is actually a bug in PostgreSQL 11. Under the hood it makes a call to fstat() to make sure the file is not a directory, and unfortunately fstat() is a 32-bit program which can't handle large files like chartevents. I tested the build on Windows with PostgreSQL 10.5 and I didn't get this error so I think it's fairly new.

The best workaround is to keep the files compressed (i.e. keep them as .csv.gz files) and use 7zip to load in the data directly from compressed files. In testing this seemed to still work. There is a pretty detailed tutorial on how to do this here: https://mimic.physionet.org/tutorials/install-mimic-locally-windows/

The brief version of above is that you keep the .csv.gz files, you add the 7zip binary to your windows environment path, and then you call the postgres_load_data_7zip.sql file to load in the data. You can use the postgres_checks.sql file after everything to make sure you loaded in all the data correctly.

edit: For your later error, where you are using this 7zip approach, I'm not sure why it's not loading. Try redownloading just the ADMISSIONS.csv.gz file and seeing if it still throws you that same error. Maybe there is a new version of 7zip which requires me to update the script or something!

like image 36
亚军吴 Avatar answered Sep 21 '22 07:09

亚军吴