Search code examples
command-linepostgresql-9.1sql-scripts

How to execute multiple sql files in postgreSQL linux?


I have many .sql files in a folder (/home/myHSH/scripts) in linux debian. I want to know the command to execute or run all sql files inside the folder into postgreSQL v9.1 database.

PostgreSQL informations:

Database name=coolDB
User name=coolUser

Nice to have: if you know how to execute multiple sql files through GUI tools too like pgAdmin3.


Solution

  • From your command line, assuming you're using either Bash or ZSH (in short, anything but csh/tcsh):

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