[PR #8188] Add support for ORDER BY CASE #10847

Open
opened 2026-01-22 16:08:53 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/8188

State: closed
Merged: Yes


I would like to propose the feature of custom ordering by utilizing a case expression. The most common platforms all support it.

SELECT e.name
FROM employees e
ORDER BY CASE e.position
WHEN 'manager' THEN 1
WHEN 'reporter' THEN 2
WHEN 'intern' THEN 3
ELSE 4
END

At the moment when custom ordering is needed most of the time one must fall back to platform specific functions (like FIELD for mysql). This feature would provide custom ordering out of the box for all supported platforms.

Validated platforms:

  • mysql
  • mariadb
  • postgres
  • sqlite
  • oracle
  • sql server

I've added 2 tests that validates using a simple and generic case expressions.

Any thoughts?

**Original Pull Request:** https://github.com/doctrine/orm/pull/8188 **State:** closed **Merged:** Yes --- I would like to propose the feature of custom ordering by utilizing a case expression. The most common platforms all support it. ```sql SELECT e.name FROM employees e ORDER BY CASE e.position WHEN 'manager' THEN 1 WHEN 'reporter' THEN 2 WHEN 'intern' THEN 3 ELSE 4 END ``` At the moment when custom ordering is needed most of the time one must fall back to platform specific functions (like `FIELD` for mysql). This feature would provide custom ordering out of the box for all supported platforms. Validated platforms: - mysql - mariadb - postgres - sqlite - oracle - sql server I've added 2 tests that validates using a simple and generic case expressions. Any thoughts?
admin added the pull-request label 2026-01-22 16:08:53 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#10847