0

I have a number of files which need to be run against a postgres database. They are stored as separate files for reasons of maintenance and configuration management. I am using this type of method to run them

acro =# \i ./psql.sql   
acro =# \i ./psql.function1.sql
acro =# \i ./psql.function2.sql
acro =# \i ./psql.function3.sql
acro =# \i ./psql.function4.sql

etc

Is there a way to batch these commands or these file names up, so that they can be run as a single interactive command ?

Thanks

2
  • cat psql.sql psql.function1.sql psql.function2.sql | psql Commented Dec 12, 2016 at 12:31
  • Thanks for the suggestion. Commented Dec 12, 2016 at 13:58

1 Answer 1

1

You can simply create a file batch.sql that looks like this:

\i ./psql.sql   
\i ./psql.function1.sql
\i ./psql.function2.sql
\i ./psql.function3.sql
\i ./psql.function4.sql

and run it with psql -f batch.sql.

Sign up to request clarification or add additional context in comments.

3 Comments

this file would need to be edited everytime a new file is added or removed.
Loop thorugh files in a directory. Something like : for f in *; do \i ./psql $f; done
Thanks for the suggestion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.