user1954209
user1954209

Reputation: 121

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.

Upvotes: 11

Views: 45553

Answers (5)

Ahmed Aboud
Ahmed Aboud

Reputation: 1322

if you are on windows use the pgsql Shell enter your server and database and user information then run without any quotes

\i D:/folder/your_table.sql

Upvotes: 0

Cathy Graichen
Cathy Graichen

Reputation: 21

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.

Upvotes: 2

GabeMeister
GabeMeister

Reputation: 1868

@DrColossos is correct. You have to use that command from the command line in the directory that contains the psql.exe executable.

Keep in mind if you are using this command to replace a database already on your system, then you have to delete that database before you run the command.

If you get weird indexing issues after you run the command please see this tutorial on how to fix it.

Upvotes: 0

DrColossos
DrColossos

Reputation: 12988

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.

Upvotes: 11

Houari
Houari

Reputation: 5621

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"

Upvotes: 18

Related Questions