Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

psql export return No such file or directory when the file exist

I run

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;"

I got

ERROR:  could not open file "/Applications/MAMP/htdocs/code/site/portal/public/csv/externals.csv" for reading: No such file or directory

But I know for sure the file is there, becase when I run

cat /Applications/MAMP/htdocs/code/site/portal/public/csv/externals.csv

I got

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"

Is it because of the permission?

-rwxrwxrwx@ 1 site  staff    307 May 24 13:46 externals.csv

I even try chomd 777 and run with sudo. But nothing seems to help!

like image 787
code-8 Avatar asked May 24 '17 17:05

code-8


1 Answers

Change that copy to \copy (https://www.postgresql.org/docs/current/static/app-psql.html#APP-PSQL-META-COMMANDS-COPY). Slightly different command that lets you copy to/from a file to your server.

The reason for the difference here is because you are connecting to a remote server (I assume), but importing a local file.


Another options is to pass your file in and have psql read from stdin like

 -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
like image 192
JNevill Avatar answered Nov 05 '22 02:11

JNevill