I am trying to import a.sql file into my new created database. I used
docker exec -it <idOfContainer> psql -U <user> <database_name>
to specify the database I want to use. Then I tried to import the.sql file to the database using the command
psql <databasename> -f "<path/to/file.sql>";
but this error appears
ERROR: syntax error at or near "psql"
LINE 1: psql <databasename> -f "<path/to/file.sql>";
^
I am new in using postgres and databases, so no idea what to do, thanks for the help!
Your docker exec is wrong, you only need the '-i'
The -it executes tty which will get you to run into your container. Importing databases can be done outside the container.
cat database.sql | docker exec -i <dockercontainername> psql -U <user> <databasename>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.