+3 votes
in Databases by (71.8k points)
I want to download the output of my SQL query to an output file - either in txt format or csv format. How can I do that?

1 Answer

+2 votes
by (56.8k points)
selected by
 
Best answer

1. To download the output as csv file, type the following command on Postgres terminal...

myproject=# copy (select place_id,place_name from places where place_type ='county court') to '/home/praveen/Downloads/test.csv';

2. To download the output as txt file, type the following command on Postgres terminal...

myproject=# copy (select place_id,place_name from places where place_type ='county court') to '/home/praveen/Downloads/test.txt';

If you are getting permission error, create a file test.csv/test.txt in the desired folder and provide read-write access to all. Also, you need to write your own select query. The query I have mentioned is just an example. :)

Related questions


...