这很简单,但不知何故,我对我的数据库的这个查询做错了。
我在下面有这个查询:
SELECT login FROM accounts WHERE login = "loginname";
当我执行这个查询时,我得到的结果是这样的:
column "loginname" does not exist
这很简单,为什么这个查询不能正常工作?我有一个登录列,我知道这个用户存在,因为我已经通过 Rails 控制台找到了这个人。为什么登录条件将其自身称为列?
最佳答案
如果要匹配字符串,请尝试使用单引号 ''
SELECT login FROM accounts WHERE login = 'loginname';
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.
关于sql - 有人可以帮我指出这个简单的 WHERE 子句有什么问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34336651/