Generate CSV file from an SQL query

1

I'm working with PostgreSQL 9.6, I tried to put:

 COPY (SELECT * FROM estado) TO E'"C:\Users\freqde\Documents\A.csv"';

But I get the following error:

 no se permiten rutas relativas para COPY hacia un archivo
    
asked by FrEqDe 04.05.2017 в 07:00
source

3 answers

4

Try to eliminate the double quotes:

COPY (SELECT * FROM estado) TO E'C:\Users\freqde\Documents\A.csv';

Remember that if your database is not on your computer, the copy will try to do it on the remote computer where the database is located.

    
answered by 10.06.2017 в 15:46
1

The easiest way is to click on the Export data to file field above in the panel and indicate the route we want.

    
answered by 12.12.2018 в 14:21
-1

I used it in the following way and it worked correctly:

COPY (SELECT * FROM tabla) TO E'/folder1/folder2/archivo.csv';

I also modified the public permissions of the csv file for writing.

    
answered by 03.01.2019 в 22:21