Skip to content

Querybuilder: Expected =, <, <=, <>, >, >=, !=, got 'IN' #12178

@PaulCombal

Description

@PaulCombal

Bug Report

Q A
Version 3.5.2

Summary

Using the querybuilder, using CASE WHEN + IN produces an error.
Using CASE WHEN with any other comparison works just fine

Current behavior

->andWhere("
CASE
  WHEN o.prop1 IS NOT NULL THEN o.propX
  WHEN o.prop2 IS NOT NULL THEN o.propY
  ELSE o.propZ
END IN (:values)
")

Produces:

[Syntax Error] line 0, col 911: Error: Expected =, <, <=, <>, >, >=, !=, got 'IN'

Indeed, using any of the listed operators work just fine.

I tried finding a workaround but didn't find any, all other alternative syntaxes produce the same issue.

Expected behavior

The above DQL works, as suggested by the SQL syntax.

How to reproduce

The first querybuilder works, where the second querybuilder doesn't:

        $this
            ->userRepository
            ->createQueryBuilder('u')
            ->andWhere('CASE WHEN u.email IS NULL THEN u.email ELSE u.email END = :value')
            ->setParameter('value', 'test')
            ->getQuery()
            ->getResult();

        $this
            ->userRepository
            ->createQueryBuilder('u')
            ->andWhere('CASE WHEN u.email IS NULL THEN u.email ELSE u.email END IN (:value)')
            ->setParameter('value', 'test')
            ->getQuery()
            ->getResult();

Thank you for the amazing work <3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions