How to execute multiple queries using psql command from bash shell?

后端 未结 4 767
天涯浪人
天涯浪人 2021-01-03 17:35

I need to execute postgresql queries from command line using psql -c command. For every psql command, it opens a new tcp connection to connect to the database server and exe

4条回答
  •  醉话见心
    2021-01-03 18:29

    -c processes only one command. Without it however psql expects commands to be passed into standard input, e.g.:

    psql -U postgres -h   << EOF
    SELECT * FROM xyz_table;
    SELECT * FROM abc_table;
    EOF
    

    Or by using echo and pipes.

提交回复
热议问题