此查詢工作正常的MySQL,但不是在PostgreSQL的:查詢工作正常的MySQL,但不是在PostgreSQL的
select
concat(hc.id, hl.languagecode) AS id,
hc.id AS category_id,
hl.languagecode AS languagecode
from language hl
join category hc
left join categorytranslation hct ON hl.languagecode = hct.languagecode and hc.id = hct.category_id;
在PostgreSQL有時我得到的錯誤:
ERROR: syntax error at end of input LINE 9: ....languagecode = hct.languagecode and hc.id = hct.category_id ^Query failed PostgreSQL said: syntax error at end of input
還是空的結果。 我正在使用Postico來測試它。
它有什麼問題?
我想要做的就是讓這樣的結果:
select
concat(hc.id, hl.languagecode) AS id,
hc.id AS category_id,
hl.languagecode AS languagecode,
hc.slug AS slug
from category hc, language hl
但我也想加入與翻譯「categorytranslation」的表。如果翻譯是可用的而不是'類別'表格。爲此,我修改了這樣的查詢:
SELECT
concat(hp.id, hl.languagecode) AS id,
hp.id AS id,
hl.languagecode AS languagecode,
hpt.languagecode as translang,
CASE WHEN (hpt.languagecode is not null and hpt.slug is not null and trim(hpt.slug) <> '')
THEN hpt.slug
ELSE hp.slug
END AS slug,
from language hl
join category hc
left join categorytranslation hct ON hl.languagecode = hct.languagecode and hc.id = hct.category_id;
連接條件看起來有點奇怪,因爲你正在做的'language'和'category'表之間的交叉連接。它是否正確? –