最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

sql - PostgreSQL CREATE USER - need for single quotes around password, no quotes for username - Stack Overflow

matteradmin6PV0评论
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
Add a comment  | 

1 Answer 1

Reset to default 5

The 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 $$.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far