Run PostgreSQL queries from the command line

前端 未结 7 1847
逝去的感伤
逝去的感伤 2020-12-12 09:40

I inserted a data into a table....I wanna see now whole table with rows and columns and data. How I can display it through command?

7条回答
  •  -上瘾入骨i
    2020-12-12 10:09

    I have no doubt on @Grant answer. But I face few issues sometimes such as if the column name is similar to any reserved keyword of postgresql such as natural in this case similar SQL is difficult to run from the command line as "\natural\" will be needed in Query field. So my approach is to write the SQL in separate file and run the SQL file from command line. This has another advantage too. If you have to change the query for a large script you do not need to touch the script file or command. Only change the SQL file like this

    psql -h localhost -d database -U postgres -p 5432 -a -q -f /path/to/the/file.sql
    

提交回复
热议问题