Shell script to execute pgsql commands in files

后端 未结 5 1736
囚心锁ツ
囚心锁ツ 2020-12-05 23:08

I am trying to automate a set of procedures that create TEMPLATE databases.

I have a set of files (file1, file2, ... fileN), each of which contains a set of pgsql com

5条回答
  •  臣服心动
    2020-12-05 23:34

    you can echo your commands to the psql input:

    for dbname in foo foofoo foobar barbar
    do
        echo """
    CREATE DATABASE $dbname TEMPLATE mytemplate1
    """ | psql
    done
    

提交回复
热议问题