2

我在 Doctrine 中有一个本机查询,它生成正确的 SQL,在 PostgreSQL 中运行。然而,该教义返回空/空结果。

public count unReadedNotifications(User $user) {

    $rsm = new ResultSetMapping();

    $sql =
        "SELECT count(ele->'status') FROM notification CROSS JOIN LATERAL jsonb_array_elements(items) status(ele) WHERE notification.id = ? and (ele->'status')::jsonb @> '1'";

    $query = $this->getEntityManager()->createNativeQuery($sql,$rsm)->setParameter('1', $user->getNotification()->getId());
    return $query->getSingleScalarResult();
}

这个 Doctrine 原生查询返回 null。如果我检查分析器,我会看到生成的查询是:

SELECT count(ele->'status') FROM notification CROSS JOIN LATERAL jsonb_array_elements(items) status(ele) WHERE notification.id = 21 and (ele->'status')::jsonb @> '1';

如果我将其复制粘贴到 pgAdmin 中,它会运行并检索所需的“2”。

所以 pgAdmin 可以给我正确的结果,但 Doctrine 不能。

有人可以看到,哪里和哪里出了问题?

教义版本:2.6.3,Postgres 是 10。

4

0 回答 0