首页 > 解决方案 > Column doens't exists in PostgreSQL (WHERE column_name = column_value)

问题描述

I have the following table in PostgreSQL:

enter image description here

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?

标签: sqlpostgresqlstring-constant

解决方案


字符常量需要单引号。(双引号用于引用标识符)


SELECT * FROM grades 
WHERE subject = 'latin';

如果您使用WHERE subject = "latin",则 DBMS 期望“latin”是一个列名,但事实并非如此。


推荐阅读