通过键加入 JSON 列在 MySQL 5.6 中给出错误但在 MySQL 8.0.19 中工作
Join by key of JSON column giving error in MySQL 5.6 but working in MySQL 8.0.19
我当前的代码是,
$query->leftJoin('templates as t', 't.id', '=', DB::Raw("CAST(revisions.value->'$.template_id' AS UNSIGNED)"));
在这种情况下,值是修订版 table 中的 JSON 列。
它在 MySQL 8.0.19 中完美运行但抛出错误
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '>"$.template_id" AS UNSIGNED) left join" in MySQL 5.6
Json 在 mysql v5.7.8 only, therefore no json operators are supported in v5.6. The column path operator (->) was added in v5.7.9 中添加了支持。您至少需要迁移到 v5.7.9 才能使此代码在 mysql.
中运行
我当前的代码是,
$query->leftJoin('templates as t', 't.id', '=', DB::Raw("CAST(revisions.value->'$.template_id' AS UNSIGNED)"));
在这种情况下,值是修订版 table 中的 JSON 列。
它在 MySQL 8.0.19 中完美运行但抛出错误
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '>"$.template_id" AS UNSIGNED) left join" in MySQL 5.6
Json 在 mysql v5.7.8 only, therefore no json operators are supported in v5.6. The column path operator (->) was added in v5.7.9 中添加了支持。您至少需要迁移到 v5.7.9 才能使此代码在 mysql.
中运行