iT邦幫忙

0

postgresql匯入.sql

想請教各位 我目前要在postgresql中匯入.sql檔,但我從網路參考幾個作法後都會顯示語法錯誤,所以想請教各位是否我執行的語法有哪裡出錯還是有其他可行的語法?

目前執行過的sql:

1.psql -U postgres -f /temp/select_1.sql
[ERROR: syntax error at or near "psql" LINE 1: psql -U postgres -f /temp/select_1.sql]

2.psql -h localhost -d SQL_Exercise -U trinity -f select_1.sql
[ERROR: syntax error at or near "psql" LINE 1: psql -h localhost -d SQL_Exercise -U trinity -f select_1....]

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

3
一級屠豬士
iT邦大師 1 級 ‧ 2021-06-16 12:07:35
最佳解答

https://www.postgresql.org/docs/current/app-psql.html
1.
在 OS Shell 下呼叫 psql 執行 file 裡的內容使用
psql -U user -d dbname -f /path/file -W
2.
當使用 psql -U user -d dbname -W
已經登入 psql 後 , 有些安裝的套件,你去 double click ,會幫你帶參數登入.
這時候要用 meta-command \i /path/file 來執行.

推測你是已經登入 psql 了,但是使用呼叫 psql, 所以psql 認為你的語法錯誤.

/images/emoticon/emoticon12.gif

我要發表回答

立即登入回答