Home > Blockchain >  Postgresql Copy Function from the Server Computer to the Client Computer
Postgresql Copy Function from the Server Computer to the Client Computer

Time:10-19

I would like to import a table from the server computer into a Client computer using the copy command. I know this is a recurring issue for users, but I have not been able to get an answer to this particular one and it's also a different scenario, and I believe this to be common.

I used a copy command to copy a Table from the server to the client computer using the code below:

COPY (Select * from Table_Name) TO 'C:\somedirectory\file.csv' DELIMITER ',' CSV HEADER;

However, I got the following

ERROR: relative path not allowed for COPY to file

My question is: How do I use the correct COPY command to copy from the server computer to the client computer in Postgres.

Thank you in anticipation

CodePudding user response:

  1. Please check if your user has read/write access to the destination folder.
  2. This is one thread I found, see if it helps

https://dba.stackexchange.com/questions/158466/relative-path-for-psql-copy-file https://postgrespro.com/list/thread-id/1116997

  1. Try with network through access using client public IP.

CodePudding user response:

How do I use the correct COPY command to copy from the server computer to the client computer in Postgres

You simply can't.

Which is clearly stated in the manual

COPY with a file name instructs the PostgreSQL server to directly read from or write to a file. The file must be accessible by the PostgreSQL user (the user ID the server runs as) and the name must be specified from the viewpoint of the server

(emphasis mine)

You need to use psql's \copy command or any other export tool that works on the client side.

  • Related