psql - save results of command to a file

后端 未结 10 1180
日久生厌
日久生厌 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:53

    From psql's help (\?):

    \o [FILE] send all query results to file or |pipe

    The sequence of commands will look like this:

    [wist@scifres ~]$ psql db
    Welcome to psql 8.3.6, the PostgreSQL interactive terminal
    
    db=>\o out.txt
    db=>\dt
    db=>\q
    

提交回复
热议问题