postgresql

Using COPY FROM in postgres - absolute filename of local file


I'm trying to import a csv file using the COPY FROM command with postgres.

The db is stored on a linux server, and my data is stored locally, i.e. C:\test.csv

I keep getting the error:

ERROR: could not open file "C:\test.csv" for reading: No such file or directory
SQL state: 58P01

I know that I need to use the absolute path for the filename that the server can see, but everything I try brings up the same error.


Solution

  • Quote from the PostgreSQL manual:

    The file must be accessible to the server and the name must be specified from the viewpoint of the server

    So you need to copy the file to the server before you can use COPY FROM.

    If you don't have access to the server, you can use psql's \copy command which is very similar to COPY FROM but works with local files. See the manual for details.