I would like search JSONB
column using query builder
If I do this SQL command in DBeaver
it works
<code>SELECT id, location
FROM post
WHERE location->>'title' LIKE '%test%'
</code>
<code>SELECT id, location
FROM post
WHERE location->>'title' LIKE '%test%'
</code>
SELECT id, location
FROM post
WHERE location->>'title' LIKE '%test%'
but it does not work using query builder
I have this basic query:
<code> public function testsql(): void
{
$qb = $this->createQueryBuilder('a');
$qb = $qb->select('a.id', 'a.location');
$qb = $qb->andWhere("a.location->>'title' LIKE :loc0");
$qb = $qb->setParameter('loc0', ' %test% ');
$query = $qb->getQuery();
$result = $query->getResult();
}
</code>
<code> public function testsql(): void
{
$qb = $this->createQueryBuilder('a');
$qb = $qb->select('a.id', 'a.location');
$qb = $qb->andWhere("a.location->>'title' LIKE :loc0");
$qb = $qb->setParameter('loc0', ' %test% ');
$query = $qb->getQuery();
$result = $query->getResult();
}
</code>
public function testsql(): void
{
$qb = $this->createQueryBuilder('a');
$qb = $qb->select('a.id', 'a.location');
$qb = $qb->andWhere("a.location->>'title' LIKE :loc0");
$qb = $qb->setParameter('loc0', ' %test% ');
$query = $qb->getQuery();
$result = $query->getResult();
}
I get error:
<code>
In QueryException.php line 23:
[Syntax Error] line 0, col 64: Error: Expected Literal, got '>'
In QueryException.php line 18:
SELECT a.id, a.location FROM AppEntityPost a WHERE a.location->>'title' LIKE :loc0
</code>
<code>
In QueryException.php line 23:
[Syntax Error] line 0, col 64: Error: Expected Literal, got '>'
In QueryException.php line 18:
SELECT a.id, a.location FROM AppEntityPost a WHERE a.location->>'title' LIKE :loc0
</code>
In QueryException.php line 23:
[Syntax Error] line 0, col 64: Error: Expected Literal, got '>'
In QueryException.php line 18:
SELECT a.id, a.location FROM AppEntityPost a WHERE a.location->>'title' LIKE :loc0
2