我一直在阅读文档,我找不到我在这里做错了什么。
我正在执行此查询:
SELECT *
FROM "parts"
INNER JOIN "categories" ON "categories"."id" = "parts"."category_id"
WHERE "categories"."name" = "cars"
我收到了这个错误:
ERROR: column "cars" does not exist
LINE 3: WHERE (categories.name = "cars")
^
********** Error **********
ERROR: column "cars" does not exist
SQL state: 42703
Character: 122
类别表:
CREATE TABLE categories
(
id serial NOT NULL,
name character varying(255),
CONSTRAINT categories_pkey PRIMARY KEY (id)
)
零件表:
CREATE TABLE parts
(
id serial NOT NULL,
category_id integer,
CONSTRAINT parts_pkey PRIMARY KEY (id)
)
非常感谢任何帮助。
答案 0 :(得分:7)
您应该对字符串常量使用单撇号:
SELECT *
FROM "parts"
INNER JOIN "categories" ON "categories"."id" = "parts"."category_id"
WHERE "categories"."name" = 'cars'
双精度意味着数据库对象。(字段,表格等)
(否则它们不是必需的,仅用于额外的,例如名称中的空格等。)