PostgreSQL:在命令行中使用psql运行SQL命令 [英] postgresql: run SQL commands using psql in commandline
本文介绍了PostgreSQL:在命令行中使用psql运行SQL命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要使用psql在命令行中运行以下三行代码。
I have the below three lines to be run in commandline using psql how can i do it.
CREATE DATABASE myproject;
CREATE USER myprojectuser WITH PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE myproject TO myprojectuser;
我只想按原样传递sql字符串。
I just want to pass the sql strings as it is.
推荐答案
按照 docs psql -c'command;'
psql -c 'CREATE DATABASE myproject;' -c "CREATE USER myprojectuser WITH PASSWORD 'password';" -c 'GRANT ALL PRIVILEGES ON DATABASE myproject TO myprojectuser;'
这篇关于PostgreSQL:在命令行中使用psql运行SQL命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文