views:

111

answers:

2

i am using postgresql 8.4 and i have some *.sql files to import into database how can i do so ?

thanx in advance!

+3  A: 

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

Bolo
its giving an error the "permission denied"
moon
@moon Maybe you don't have access rights to the SQL files? What operating system are you on?
Bolo
it asks for a password which password i have to write in???
moon
i am using windows XP sp 2
moon
@moon It's the password associated with your PostgreSQL user (the user-pass pair is stored in PostgreSQL).
Bolo
@moon I suggest that you split your problem into three stages: 1) make sure that you can get `psql` running. 2) make sure your user has the necessary write privileges, such as: `CREATE`, `INSERT`, `UPDATE`, etc. 3) import the SQL files. As far as I understand, you're at stage 1 now.
Bolo
A: 

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.

moon