为什么postgresql不能执行其'where'子句具有键匹配谓词的select语句?

时间:2016-12-07 22:33:39

标签: sql postgresql

select * from note where noteKey = 1

此声明给出了以下错误。

ERROR:  column "notekey" does not exist
LINE 1: select * from note where noteKey = 1
                                 ^
HINT:  Perhaps you meant to reference the column "note.noteKey".

我试过note.noteKey,但得到了同样的错误。 (我顺便使用postico,而noteKey是表格的主键)。

声明可能有什么问题?

1 个答案:

答案 0 :(得分:0)

您需要连接psql并运行\d note

如果显示该列名为noteKey且大写为K,那么您有两个选项

  1. 重命名列ALTER TABLE note RENAME COLUMN "noteKey" TO notekey;
  2. 永远使用双引号"进行查询。
  3. 在PostgreSQL中,我们从不引用列名。这迫使他们对上限敏感。如果没有引用,他们会自动降低成绩。

    select * from note where noteKey = 1
    

    相同
    select * from note where notekey = 1
    

    不同
    select * from note where "noteKey" = 1