ERROR: could not stat file “XX.csv”: Unknown error

后端 未结 5 487
我在风中等你
我在风中等你 2020-12-16 14:43

I run this command:

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

In Windows 7, it successfully imports CSV f

相关标签:
5条回答
  • 2020-12-16 14:52

    It seems this is not a database problem, but a problem of psql / pgadmin. The workaround is using an admin software from the previous psql versions:

    1. Use the existing PostgreSQL 11 database
    2. Install psql or pgadmin from the PostgreSQL 10 installation and use it to upload the file (with the command shown in the question)

    Hope this helps anyone coming across the same problem.

    0 讨论(0)
  • 2020-12-16 14:57

    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!

    0 讨论(0)
  • 2020-12-16 15:06

    With pgAdmin and AWS, I used CSVSplitter to split into files less than 1GB. Lame, but worked. pgAdmin import appends to the existing table. (Changed escape character from ' to " in order to avoid error due to unquoted text in the source file. Typically I apply quotes in LibreOffice, but these files were too big to open.)

    0 讨论(0)
  • 2020-12-16 15:14

    For anyone else who googled this Postgres error message after attempting to work with a >1gb file in Postgres 11, I can confirm that @亚军吴's answer above is spot-on. It is indeed a size issue.

    I tried a different approach, though, than @亚军吴's and @Loren's: I simply uninstalled Postgres 11 and installed the stable version of Postgres 10.7. (I'm on Windows 10, by the way, in case that matters.)

    I re-ran the original code that had prompted the error and voila, a few minutes later I'd filled in a new table with data from a medium-ish-size csv file (~3gb). I initially tried to use CSVSplitter, per @Loren, which was working fine until I got close to running out of storage space on my machine. (Thanks, Battlefield 5.)

    In my case, there isn't anything in PGSQL 11 that I was relying on that wasn't in version 10.7, so I think this could be a good solution for anyone else who runs into this problem. Thanks everyone above for contributing, especially to the OP for posting this in the first place. I cured a huge, huge headache!

    0 讨论(0)
  • 2020-12-16 15:17

    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.

    0 讨论(0)
提交回复
热议问题