psql -E -U siteportal -d portal -h 172.19.242.32 -c "COPY externals (id,logo_path,favicon_path,cover_path,header,description,sign_enable,sign_text,footer_logo_enable,footer_logo_path,footer_text,created_at,updated_at) FROM '/Applications/MAMP/htdocs/code/site/portal/public/csv/externals.csv' DELIMITER ',' csv;"
ERROR: could not open file "/Applications/MAMP/htdocs/code/site/portal/public/csv/externals.csv" for reading: No such file or directory
但我确定文件存在,因为当我运行时
cat /Applications/MAMP/htdocs/code/site/portal/public/csv/externals.csv
我得到了
1,"/images/account/operator/logo.png","/images/account/operator/favicon.png","/images/account/operator/external.png","site Portal","Log in using your credentials",1,"This is a secure page",1,"/images/account/operator/footer_logo.png","© 2017 site Networks Inc.","2016-12-22 13:37:42","2017-01-31 14:22:11"
是否因为许可?
-rwxrwxrwx@ 1 site staff 307 May 24 13:46 externals.csv
我甚至尝试chomd 777
并使用sudo
。但似乎没有任何帮助!
答案 0 :(得分:5)
将copy
更改为\copy
(https://www.postgresql.org/docs/current/static/app-psql.html#APP-PSQL-META-COMMANDS-COPY)。稍微不同的命令,允许您将文件复制到服务器或从文件复制到服务器。
这里产生差异的原因是因为您连接到远程服务器(我假设),但导入本地文件。
另一个选择是传入你的文件,并从stdin中读取psql
,如
-c "copy externals (id,logo_path,favicon_path,cover_path,header,description,sign_enable,sign_text,footer_logo_enable,footer_logo_path,footer_text,created_at,updated_at) from STDIN with delimiter as ','" < /Applications/MAMP/htdocs/code/benu/ssc-portal/public/csv/externals.csv