我想在一行中创建一个角色/用户。以下是我尝试过的:
psql -U postgres -c 'createuser my_app with createdb login password 'my_password';'
psql: warning: extra command-line argument "with" ignored
psql: warning: extra command-line argument "createdb" ignored
psql: warning: extra command-line argument "login" ignored
psql: warning: extra command-line argument "password" ignored
psql: warning: extra command-line argument "'my_password';'" ignored
psql: FATAL: database "my_app" does not exist代替createuser,我也尝试了create user和create role,但是无论如何,我也会得到相同的错误。我在Windows上使用(PostgreSQL) 9.6.2
我做错了什么?
更新:
我试着用双引号,但出于某种原因,postgres似乎不喜欢我的双引号。在单引号中使用双引号神秘地工作->谢谢@Laurenz
psql -U postgres -c "createuser my_app with createdb login password 'my_password';"
ERROR: syntax error at or near "createuser"
LINE 1: createuser my_app with createdb login password 'my_password'...发布于 2018-05-19 22:46:27
createuser不是一个SQL命令,所以这是行不通的。
CREATE USER是正确的,但您不能将单引号嵌套在这样的单引号中。
它应该是
psql -U postgres -c "CREATE USER my_app CREATEDB PASSWORD 'my_password'"https://stackoverflow.com/questions/50429699
复制相似问题