Import .sql file in pgadmin iii

user1954209 picture user1954209 · Mar 6, 2014 · Viewed 39.4k times · Source

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.

Answer

Houari picture Houari · Mar 6, 2014

I think that the best way to import an sql file is using the psql tool like this:

psql -U postgres -h localhost -d my_database -f "C:/Users/umair/Downloads/school_management_system(1).sql"