PostgreSQL 中的基本 DELETE 命令检测值作为列名

Basic DELETE commands in PostgreSQL detecting value as column name

我正在尝试使用 pgAdmin4 在 PostgreSQL 中删除一行。 这是我的命令:

DELETE FROM commissions_user 
WHERE first_name = "Steven";

出于某种原因,错误指出

ERROR:  column "Steven" does not exist
LINE 2: WHERE first_name = "Steven";
                           ^
SQL state: 42703
Character: 50

奇怪,为什么“Steven”被检测为列名,列名不应该是first_name吗?

改用单引号

DELETE FROM commissions_user 
WHERE first_name = 'Steven';

双引号可以用table和列,字符串可以用单引号

例如

DELETE FROM "commissions_user"
WHERE "first_name" = 'Steven';

https://www.postgresql.org/docs/current/sql-syntax-lexical.html
双引号:

A convention often used is to write key words in upper case and names in lower case, e.g.:

UPDATE my_table SET a = 5;

There is a second kind of identifier: the delimited identifier or quoted identifier. It is formed by enclosing an arbitrary sequence of characters in double-quotes ("). A delimited identifier is always an identifier, never a key word. So "select" could be used to refer to a column or table named “select”, whereas an unquoted select would be taken as a key word and would therefore provoke a parse error when used where a table or column name is expected. The example can be written with quoted identifiers like this:
UPDATE "my_table" SET "a" = 5;


单引号:
https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS

A string constant in SQL is an arbitrary sequence of characters bounded by single quotes ('), for example 'This is a string'. To include a single-quote character within a string constant, write two adjacent single quotes, e.g., 'Dianne''s horse'. Note that this is not the same as a double-quote character (")