Pagination not working when SimpleArithmetic is used in order by #6285

Closed
opened 2026-01-22 15:30:08 +01:00 by admin · 1 comment
Owner

Originally created by @Seb33300 on GitHub (Aug 19, 2019).

Originally assigned to: @lcobucci on GitHub.

Bug Report

Q A
BC Break no
Version >= 2.6

Summary

When using Paginatoron a query using a SimpleArithmetic expression in the ORDER BY, I am encountering a MySQL error:

SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a ORDER BY a.topic + 0 ASC

Result in:

PDOException: SQLSTATE[HY000]: General error: 3065 Expression #1 of ORDER BY clause is not in SELECT list, references column 'a0_.topic' which is not in SELECT list; this is incompatible with DISTINCT

This is because the Paginator handles only PathExpression to prevent this.

Here is the PR to fix this: https://github.com/doctrine/orm/pull/7803

Originally created by @Seb33300 on GitHub (Aug 19, 2019). Originally assigned to: @lcobucci on GitHub. ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | no | Version | >= 2.6 #### Summary When using `Paginator`on a query using a `SimpleArithmetic` expression in the `ORDER BY`, I am encountering a MySQL error: ```sql SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a ORDER BY a.topic + 0 ASC ``` Result in: > PDOException: SQLSTATE[HY000]: General error: 3065 Expression #1 of ORDER BY clause is not in SELECT list, references column 'a0_.topic' which is not in SELECT list; this is incompatible with DISTINCT This is because the `Paginator` handles only `PathExpression` to prevent this. Here is the PR to fix this: https://github.com/doctrine/orm/pull/7803
admin added the BugInvalid labels 2026-01-22 15:30:08 +01:00
admin closed this issue 2026-01-22 15:30:08 +01:00
Author
Owner

@lcobucci commented on GitHub (Oct 1, 2019):

As explained in https://github.com/doctrine/orm/pull/7803#pullrequestreview-295948417 we should rather use HIDDEN fields to be able to have arithmetic operations in ORDER BY. So the query should rather be:

SELECT a, a.topic + 0 AS HIDDEN my_sum FROM Doctrine\Tests\Models\CMS\CmsArticle a ORDER BY my_sum ASC

Closing as invalid here as well.

@lcobucci commented on GitHub (Oct 1, 2019): As explained in https://github.com/doctrine/orm/pull/7803#pullrequestreview-295948417 we should rather use `HIDDEN` fields to be able to have arithmetic operations in `ORDER BY`. So the query should rather be: ```sql SELECT a, a.topic + 0 AS HIDDEN my_sum FROM Doctrine\Tests\Models\CMS\CmsArticle a ORDER BY my_sum ASC ``` Closing as invalid here as well.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6285