Reputation: 741
I am using pgAdmin version 4.3 and i want to export one table data to CSV file. I used this query
COPY (select * from product_template) TO 'D:\Product_template_Output.csv' DELIMITER ',' CSV HEADER;
but it shows error
a relative path is not allowed to use COPY to a file
How can I resolve this problem any help please ?
Upvotes: 43
Views: 105699
Reputation: 107
Congrats!!!
Upvotes: 0
Reputation: 351
If your PgAdmin instance resides in a remote server, the aforementioned solutions might not be handy for you if you do not have remote access to the server. In this case, simply select all the query data and copy it. Open an excel file and you could paste it. Simple !! Tweaked. You might have tough time if your query result is too much though.
Upvotes: 4
Reputation: 881
From the query editor, once you have executed your query, you just have to click on the "Download as CSV (F8)" button or use F8 key.
Source pgAdmin 4 Query Toolbar
Upvotes: 76
Reputation: 1193
Use absolute paths or cd to a known location so that you can ignore the path. For example cd into documents directory then run the commands there.
If you are able to cd into your documents directory, then the command would be like this:
Assuming you are want to use PSQL from the command line. cd ~/Documents && psql -h host -d dbname -U user
\COPY (select * from product_template) TO 'Product_template_Output.csv' DELIMITER ',' CSV HEADER;
The result would be Product_template_Output.csv in your current working directory(Documents folder).
Again using psql.
Upvotes: 11
Reputation: 1054
Try this command:
COPY (select * from product_template) TO 'D:\Product_template_Output.csv' WITH CSV;
Upvotes: 0
Reputation: 246043
You have to remove the double quotes:
COPY (select * from product_template) TO 'D:\Product_template_Output.csv'
DELIMITER ',' CSV HEADER;
Upvotes: 3