我試圖在登錄到資料庫后執行 sql 查詢。盡管 Postgres 官方檔案提到了選項 c,但我一直收到錯誤訊息,說 command , -c, --c 不是有效選項。
下面是我的 shell 腳本檔案中的行。
psql "host='localhost' port=xxxx dbname='xxxxx' user='xxxx' password='xxxxx' -c='sql string'"
uj5u.com熱心網友回復:
您正在混合長短選項語法......
這個:
#!/bin/sh
echo "Connect to DB"
psql "host='localhost' port=xxxx dbname='xxxxx' user='xxxx' password='xxxxx'" -c='select * from pg_stat_archive'
需要是:
#!/bin/sh
echo "Connect to DB"
psql "host='localhost' port=xxxx dbname='xxxxx' user='xxxx' password='xxxxx'" -c 'select * from pg_stat_archive'
等號僅用于長格式: --command=command
uj5u.com熱心網友回復:
在 shell 腳本中使用 here doc 以避免 -c 的終止和行為
psql <<EOF \x SELECT * FROM foo; EOF
有關特定行為和示例,請參閱此 https://www.postgresql.org/docs/12/app-psql.html
uj5u.com熱心網友回復:
-c 選項必須根據@Charles Duffy 的評論放在前面
#!/bin/sh echo "Connect to DB" psql -c 'select * from any_table' "host='localhost' port=xxxx dbname='xxxxx' user='xxxx' password='xxxxx'"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/336369.html
標籤:linux PostgreSQL 贝壳 查询语句
