I want to import a sql file in PostgreSQL. I am using pgadmin iii. I create an sql file in phpmyadmin and now i want to import same file in pgadmin iii. I am doing following but it didn't work for me. I select schema of the database in pgadmin iii and after that I try to execute following query:
\i C:/Users/umair/Downloads/school_management_system(1).sql
but it generates an error and the error is:
ERROR: syntax error at or near "\"
LINE 1: \i C:/Users/umair/Downloads/school_management_system(1).sql
^
********** Error **********
ERROR: syntax error at or near "\"
SQL state: 42601
Character: 1
Please help me out.
Firstly, we create a full backup of the database in the form of an SQL file. Next, in the pgAdmin tool, we create a new database for restoring the SQL file. Now, the list will contain the newly created database. So, we right-click the database and select the Restore option.
You cannot import a plain *sql file via pgAdmin. It only supports the custom import as created via (pg_restore - that pgAdmin uses in the background).
You should use the command line, NOT pgAdmin for this task. Your comment to another answer suggests that you executed the command from pgAdmin. This will not work.
psql -U username -h localhost -d database_name < path/to/your/file.sql
Note that -h is optional and it depends on how you connect to the system.
On Windows, I can only run the psql command from a regular CMD console window, not from a bash window like I might get if I have git installed. You should have psql.exe somewhere like C:\Program Files\PostgreSQL\9.4\bin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With