At times it's useful to direct the output of SQL command to a text file. For that follow the following steps.
- Got to database using psql command through console. For example if database is abc then do
- At psql prompt do the following, if data.csv is the file where you want to pipe
- Run the query
Now go the location and you can see the text file with the data in it.