Symfony自定义查询用JSON_TABLE报MariaDB语法错误求助
Symfony自定义仓库查询的MariaDB语法错误排查
我在Symfony中编写了一个用于计算价格的自定义仓库查询,代码如下:
$sql = " SELECT SUM(sub.totalPriceWT) AS totalPrice, c.label FROM ( SELECT v.id, ( SELECT SUM(priceWT) FROM JSON_TABLE( JSON_UNQUOTE(JSON_EXTRACT(v.dac, '$.bdc.service.operator.entries[*].priceWT')), '$[*]' COLUMNS(priceWT DECIMAL(10, 2) PATH '$') ) der ) AS totalPriceWT FROM valid v JOIN sheet s ON v.sheet_id = s.id JOIN step st ON s.step_id = st.id WHERE JSON_UNQUOTE(JSON_EXTRACT(v.dac, '$.type')) = 'bdc' AND ( (YEAR(s.sent_date) = :currentYear AND CAST(JSON_EXTRACT(v.dac, '$.anticipated') AS SIGNED) = :anticipated2) OR (YEAR(s.sent_date) = :previousYear AND CAST(JSON_EXTRACT(v.dac, '$.anticipated') AS SIGNED) = :anticipated1) ) AND s.perimeter_id = :perimeter AND JSON_UNQUOTE(JSON_EXTRACT(v.dac, '$.bdc.service.operator.entries')) IS NOT NULL AND st.slug != 'rejetee' ) AS sub JOIN valid v2 ON sub.id = v2.id JOIN sheet s2 ON v2.sheet_id = s2.id JOIN cost_center c ON s2.cost_center_id = c.id GROUP BY c.id "; $conn = $this->manager->getConnection(); $stmt = $conn->prepare($sql); $stmt->bindValue('perimeter', $perimeter->getId()); $stmt->bindValue('currentYear', $year); $stmt->bindValue('previousYear', $year - 1); $stmt->bindValue('anticipated1', 1); $stmt->bindValue('anticipated2', 0); $resultSet = $stmt->executeQuery(); $resultBDC = $resultSet->fetchAllAssociative();
执行该查询时出现如下错误:
An exception occurred while executing a query: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '( JSON_UNQUOTE(JSON_EXTRACT(v.dac, '$.bdc.serv...' at line 9
原本以为使用的是MySQL,但错误提示指向MariaDB,后确认实际运行环境为MariaDB。执行php bin/console debug:container --env-vars和php bin/console debug:config doctrine dbal命令查看,输出显示为MySQL/pdo_mysql,无法定位问题所在,请求帮助排查。
内容的提问来源于stack exchange,提问作者Laura Leroy
相关产品推荐
相关产品推荐

