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 $$
.
name follows the rules for SQL identifiers: either unadorned without special characters, or double-quoted.
– Ali Khan Commented Nov 17, 2024 at 13:24