【PgSQL管理】命令行下執行SQL


#-c實現命令行下執行SQL

$ psql -h localhost -c "SELECT datname FROM pg_database where datistemplate = false and datname != 'postgres';"
datname
---------
monitor
dw
(2 rows)

#-o輸出結果至文件

$ psql -h localhost -c "SELECT datname FROM pg_database where datistemplate = false and datname != 'postgres';" -o db.list
[postgres@t3-jiantou-tkhicomcse-db01-train ~]$ ll
total 5976
-rw-rw-r-- 1 postgres postgres 54 Apr 6 14:21 db.list

#-t, --tuples-only        print rows only

$ psql -h localhost -t -c "SELECT datname FROM pg_database where datistemplate = false and datname != 'postgres';"
monitor
dw

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM