Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How do call multiple sql files in a single sql file, in postgres

For example I have aaa.sql, bbb.sql, ccc.sql.

I want to execute this 3 files from xxx.sql.

Can anyone suggest me how to do this.

share|improve this question
add comment

1 Answer

If you are running these files through psql you want the \i directive ("execute commands from file").

xxx.sql:

\i aaa.sql
\i bbb.sql
\i ccc.sql

If you are passing these through some other program you will need to combine the files yourself - I do not believe there is any SQL-standard way of executing external files.

share|improve this answer
    
Thank you for the reply. I will test and confirm if I was able to achieve it or not –  Trip Feb 3 '12 at 22:13
    
Doesn't look like working yet Not sure if I am missing something. do I need semi colon at the end??? -Not Really !!! –  Trip Feb 4 '12 at 0:04
    
You need to be more specific than "not working" - I assure you this does work -- Refer to the psql manual –  voretaq7 Feb 4 '12 at 1:09
    
It worked. Finally :-) Thanku Problem was -- it was not able to recognize the file and O specifiled the relative path for the file and its working Thank you once again –  Trip Feb 6 '12 at 15:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.