Answer the question
In order to leave comments, you need to log in
SQL query that works in SQLite and PgSql with json?
Doctrine 2.6 + Postgresql .9.6
$rsm = new ResultSetMapping();
$rsm->addEntityResult(Notification::class, 'notificationTableAlias');
$rsm->addFieldResult('notificationTableAlias', 'id', 'id');
$query = $this->_em->createNativeQuery(
<<<EOT
SELECT id,
COUNT(id)
FROM notification
WHERE statuses_values::jsonb = ?::jsonb
AND user_id = ?
GROUP BY notification.id
EOT
,
$rsm
);
$query->setParameter(1, '"[]"');
$query->setParameter(2, $loggedUserId);
$results = $query->execute();
return \count($results);
WHERE statuses_values = ?
SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: json = unknown
LINE 4: WHERE statuses_values = $1
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.").
if ($this->_em->getConnection()->getDriver() instanceof AbstractSQLiteDriver) {
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question