psql - save results of command to a file

后端 未结 10 1186
日久生厌
日久生厌 2020-12-12 09:10

I\'m using psql\'s \\dt to list all tables in a database and I need to save the results.

What is the syntax to export the results of a psql command to a

10条回答
  •  隐瞒了意图╮
    2020-12-12 09:46

    Use the below query to store the result in a CSV file

    \copy (your query) to 'file path' csv header;
    

    Example

    \copy (select name,date_order from purchase_order) to '/home/ankit/Desktop/result.csv' cvs header;
    

    Hope this helps you.

提交回复
热议问题