[PostgreSQL] Error : could not open file for writing:Permission denied ; You may want a client-side facility such as psql’s \copy
PostgreSQL執行copy語法要Export匯出時,出現以下錯誤訊息的解決方法。
ERROR : could not open file “xxxx” for writing:Permission denied
HINT : Copy To instructs the PostgreSQL server process to write a file. You may want a client-side facility such as psql’s \copy
事情緣由
輸入匯出資料語法:
copy (select * from TableName) To 'C:\file.csv' delimiter ',' csv HEADER ENCODING 'UTF8'
出現錯誤訊息: 顯示不被允許開啟檔案。
解決方法
一.檔案不要放在C槽。
二.使用SQL Shell( psql)執行。
開啟PostgreSQL的SQL Shell。
連線至Server後,執行以下語法,即可匯出。
\copy (select * from TableName) To 'C:\file.csv' delimiter ',' csv HEADER ENCODING 'UTF8'