sqlpostgresql

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


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.


Solution

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