Shell script to execute pgsql commands in files

后端 未结 5 1729
囚心锁ツ
囚心锁ツ 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:33

    For that use case where you have to do it....

    Here is a script I've used for importing JSON into PostgreSQL (WSL Ubuntu), which basically requires that you mix psql meta commands and SQL in the same command line. Note use of the somewhat obscure script command, which allocates a pseudo-tty:

    $ more update.sh
    #!/bin/bash
    wget .json
    echo '\set content `cat $(ls -t .json.* | head -1)` \\ delete from ; insert into  values(:'"'content'); refresh materialized view ; " | PGPASSWORD= psql -h  -U  -d 
    $ 
    
        

    提交回复
    热议问题