Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import .sql file in pgadmin iii

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.

like image 566
user1954209 Avatar asked Mar 06 '14 07:03

user1954209


People also ask

How do I Import a SQL file into pgAdmin III?

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.


2 Answers

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.

like image 184
DrColossos Avatar answered Sep 23 '22 00:09

DrColossos


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.

like image 37
Cathy Graichen Avatar answered Sep 23 '22 00:09

Cathy Graichen