Unable tu use LIKE on numbers and subqueries #5479

Open
opened 2026-01-22 15:08:47 +01:00 by admin · 5 comments
Owner

Originally created by @Seb33300 on GitHub (Mar 27, 2017).

Hi,

When trying to use a LIKE condition on number and sub queries:

WHERE 1500 LIKE '15%'

or

WHERE (SELECT name FROM table WHERE id = 1) LIKE 'Jo%'

I am having a DQL syntax error query exception:

Error: Expected =, <, <=, <>, >, >=, !=, got 'LIKE'

I am able to use theirs conditions in SQL, so is it a DQL bug?

Thanks

Originally created by @Seb33300 on GitHub (Mar 27, 2017). Hi, When trying to use a `LIKE` condition on number and sub queries: ```sql WHERE 1500 LIKE '15%' ``` or ```sql WHERE (SELECT name FROM table WHERE id = 1) LIKE 'Jo%' ``` I am having a DQL syntax error query exception: > Error: Expected =, <, <=, <>, >, >=, !=, got 'LIKE' I am able to use theirs conditions in SQL, so is it a DQL bug? Thanks
admin added the ImprovementMissing Tests labels 2026-01-22 15:08:47 +01:00
Author
Owner

@Ocramius commented on GitHub (Mar 30, 2017):

LIKE works with a StringExpression as per http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#scalar-and-type-expressions

Does it work when using a placeholder, instead of a hardcoded string?

@Ocramius commented on GitHub (Mar 30, 2017): `LIKE` works with a `StringExpression` as per http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#scalar-and-type-expressions Does it work when using a placeholder, instead of a hardcoded string?
Author
Owner

@Seb33300 commented on GitHub (Mar 31, 2017):

I hardcoded for the example, but I have the same issue with placeholder binded with setParameter.

@Seb33300 commented on GitHub (Mar 31, 2017): I hardcoded for the example, but I have the same issue with placeholder binded with `setParameter`.
Author
Owner

@Seb33300 commented on GitHub (Oct 12, 2017):

This issue also happens when using LIKE with CASE WHEN:

WHERE (CASE WHEN field = 'value' THEN 'ok' ELSE 'ko' END) LIKE 'ok%'
@Seb33300 commented on GitHub (Oct 12, 2017): This issue also happens when using `LIKE` with `CASE WHEN`: ``` sql WHERE (CASE WHEN field = 'value' THEN 'ok' ELSE 'ko' END) LIKE 'ok%' ```
Author
Owner

@lcobucci commented on GitHub (Oct 29, 2017):

@Seb33300 could you please send us a failing test case that reproduces that behaviour? It would help us a lot to identify and fix the issue you're describing.

You can find examples on 388afb46d0/tests/Doctrine/Tests/ORM/Functional/Ticket

@lcobucci commented on GitHub (Oct 29, 2017): @Seb33300 could you please send us a failing test case that reproduces that behaviour? It would help us a lot to identify and fix the issue you're describing. You can find examples on https://github.com/doctrine/doctrine2/tree/388afb46d0cb3ed0c51332e8df0de9e942c2690b/tests/Doctrine/Tests/ORM/Functional/Ticket
Author
Owner

@Majkl578 commented on GitHub (Dec 9, 2017):

This isn't a bug actually, it's simply behavior that is currently not supported by the parser and language.

@Majkl578 commented on GitHub (Dec 9, 2017): This isn't a bug actually, it's simply behavior that is currently not supported by the parser and language.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5479