SimpleConditionalExpressions can not parse CASE ... BETWEEN #7445

Open
opened 2026-01-22 15:51:46 +01:00 by admin · 0 comments
Owner

Originally created by @hubipe on GitHub (Nov 27, 2024).

Bug Report

Parser can not parse this DQL:

SELECT o.id
FROM Entity o
WHERE CASE o.vatIncluded WHEN TRUE THEN o.priceVat ELSE o.priceWoVat END BETWEEN 100 AND 300

The exception Expected =, <, <=, <>, >, >=, !=, got 'BETWEEN' is raised instead of successful parsing.
The only way around I found about it was to wrap the CASE to a function:

SELECT o.id
FROM Entity o
WHERE ABS(CASE o.vatIncluded WHEN TRUE THEN o.priceVat ELSE o.priceWoVat END) BETWEEN 100 AND 300

In this case, the query is parsed successfully.
It is worth noting, that adding parentheses anywhere won't help.

Q A
Version 2.19.6 and 2.5.14

Current behavior

Parser raises exception

Expected behavior

Parser should parse the query successfully

How to reproduce

Run this in PHP:

$em->createQuery('SELECT o.id
FROM Entity o
WHERE CASE o.vatIncluded WHEN TRUE THEN o.priceVat ELSE o.priceWoVat END BETWEEN 100 AND 300')->getAST();

You'll get an exception

Originally created by @hubipe on GitHub (Nov 27, 2024). ### Bug Report Parser can not parse this DQL: ```sql SELECT o.id FROM Entity o WHERE CASE o.vatIncluded WHEN TRUE THEN o.priceVat ELSE o.priceWoVat END BETWEEN 100 AND 300 ``` The exception Expected =, <, <=, <>, >, >=, !=, got 'BETWEEN' is raised instead of successful parsing. The only way around I found about it was to wrap the CASE to a function: ```sql SELECT o.id FROM Entity o WHERE ABS(CASE o.vatIncluded WHEN TRUE THEN o.priceVat ELSE o.priceWoVat END) BETWEEN 100 AND 300 ``` In this case, the query is parsed successfully. It is worth noting, that adding parentheses anywhere won't help. | Q | A |-------------------------------------------- | ------ | Version | 2.19.6 and 2.5.14 #### Current behavior Parser raises exception #### Expected behavior Parser should parse the query successfully #### How to reproduce Run this in PHP: ```php $em->createQuery('SELECT o.id FROM Entity o WHERE CASE o.vatIncluded WHEN TRUE THEN o.priceVat ELSE o.priceWoVat END BETWEEN 100 AND 300')->getAST(); ``` You'll get an exception
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7445