admin管理员组文章数量:1026104
CREATE USER test_user WITH PASSWORD 'test_password'
Password value needs single quotes, username doesn't. I just wonder why this is so? Both look like input parameters (strings) but are treated differently.
CREATE USER test_user WITH PASSWORD 'test_password'
Password value needs single quotes, username doesn't. I just wonder why this is so? Both look like input parameters (strings) but are treated differently.
Share Improve this question edited Nov 17, 2024 at 15:22 Mark Rotteveel 110k230 gold badges156 silver badges225 bronze badges asked Nov 17, 2024 at 13:00 vtm11vtm11 4013 silver badges9 bronze badges 3 |1 Answer
Reset to default 5The username is an identifier, which is either an unquoted, simple identifier, or a quoted identifier a.k.a. delimited identifier (which are enclosed in double quotes "
). In other words, a username is similar to a table name, column name, etc.
A password however, is a string, and must be provided as a string literal (a.k.a. string constants in PostgreSQL documentation), and as such must be enclosed by single quotes '
or dollar quotes $$
.
CREATE USER test_user WITH PASSWORD 'test_password'
Password value needs single quotes, username doesn't. I just wonder why this is so? Both look like input parameters (strings) but are treated differently.
CREATE USER test_user WITH PASSWORD 'test_password'
Password value needs single quotes, username doesn't. I just wonder why this is so? Both look like input parameters (strings) but are treated differently.
Share Improve this question edited Nov 17, 2024 at 15:22 Mark Rotteveel 110k230 gold badges156 silver badges225 bronze badges asked Nov 17, 2024 at 13:00 vtm11vtm11 4013 silver badges9 bronze badges 3- 3 While the password is a string literal, the user name is an identifier and it doesn't necessarily need to be wrapped in quotes as mentioned here postgresql./docs/7.1/user-manag.html. – Ali Khan Commented Nov 17, 2024 at 13:22
-
1
From the docs:
name follows the rules for SQL identifiers: either unadorned without special characters, or double-quoted.
– Ali Khan Commented Nov 17, 2024 at 13:24 - 1 @AliKhan Please link to the "current" version, not one that has been EOL for almost 2 decades... postgresql./docs/current/user-manag.html – Frank Heikens Commented Nov 17, 2024 at 20:11
1 Answer
Reset to default 5The username is an identifier, which is either an unquoted, simple identifier, or a quoted identifier a.k.a. delimited identifier (which are enclosed in double quotes "
). In other words, a username is similar to a table name, column name, etc.
A password however, is a string, and must be provided as a string literal (a.k.a. string constants in PostgreSQL documentation), and as such must be enclosed by single quotes '
or dollar quotes $$
.
本文标签:
版权声明:本文标题:sql - PostgreSQL CREATE USER - need for single quotes around password, no quotes for username - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745634176a2160343.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
name follows the rules for SQL identifiers: either unadorned without special characters, or double-quoted.
– Ali Khan Commented Nov 17, 2024 at 13:24