Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import existing *.sql files in PostgreSQL 8.4?

I am using PostgreSQL 8.4, and I have some *.sql files to import into a database. How can I do so?

like image 884
Badr Avatar asked Aug 03 '10 06:08

Badr


2 Answers

From the command line:

psql -f 1.sql psql -f 2.sql 

From the psql prompt:

\i 1.sql \i 2.sql 

Note that you may need to import the files in a specific order (for example: data definition before data manipulation). If you've got bash shell (GNU/Linux, Mac OS X, Cygwin) and the files may be imported in the alphabetical order, you may use this command:

for f in *.sql ; do psql -f $f ; done 

Here's the documentation of the psql application (thanks, Frank): http://www.postgresql.org/docs/current/static/app-psql.html

like image 61
Bolo Avatar answered Oct 07 '22 10:10

Bolo


in command line first reach the directory where psql is present then write commands like this:

psql [database name] [username] 

and then press enter psql asks for password give the user password:

then write

> \i [full path and file name with extension] 

then press enter insertion done.

like image 44
Badr Avatar answered Oct 07 '22 09:10

Badr