sql - Column doens't exists in PostgreSQL (WHERE column_name = column_value)
问题描述
I have the following table in PostgreSQL:
id and grade are INTs, note and subject both VARCHARs
When I run the command:
SELECT * FROM grades
WHERE subject = "latin";
I get the following error:
In pgAdmin4: ERROR: column "latin" does not exist LINE 2: WHERE subject = "latin" ^ SQL state: 42703 Character: 37
And in cmd: ERROR: column "latin" does not exist LINE 1: SELECT * FROM upisi WHERE subject = "latin";
I'm coming from MySQL so I thought this would work. Works fine if I put grade = something in the WHERE clause. Any idea why this might be the case?
解决方案
字符常量需要单引号。(双引号用于引用标识符)
SELECT * FROM grades
WHERE subject = 'latin';
如果您使用WHERE subject = "latin"
,则 DBMS 期望“latin”是一个列名,但事实并非如此。
推荐阅读
- resharper - 是否可以创建自定义 JetBrain.Annotations?
- python - 如何保护内置类型不被覆盖(分配给)它们的方法?
- mysql - mysql用户创建错误42000
- python - 从多个 Excel 文件中检索值
- c# - 我们可以分别将日期和时间值添加到 DateTime 变量吗?
- python - elasticsearch dsl扫描结果
- html - Ionic 3 如何为项目动态添加属性
- c++ - 是否有浮点指数偏差的规范?
- spring-boot - Zuul + Ribbon Retry - maxAutoRetries 不起作用,只重试一次
- javascript - 如何在具有空数组的 React 组件中定义 .map 列表?