Postgres COPY FROM csv file- No such file or directory

nerdenator picture nerdenator · May 17, 2013 · Viewed 30k times · Source

I'm trying to import a (rather large) .txt file into a table geonames in PostgreSQL 9.1. I'm in the /~ directory of my server, with a file named US.txt placed in that directory. I set the search_path variable to geochat, the name of the database I'm working in. I then enter this query:

COPY geonames
FROM 'US.txt',
DELIMITER E'\t',
NULL 'NULL');

I then receive this error:

ERROR: could not open file "US.txt" for reading: No such file or directory.

Do I have to type in \i US.txt or something similar first, or should it just get it from the present working directory?

Answer

jvdw picture jvdw · Nov 10, 2014

Maybe a bit late, but hopefully useful:

Use \copy instead

https://wiki.postgresql.org/wiki/COPY

jvdw