Alias can't be used in functions, causes SqlWalker to crash #6318

Closed
opened 2026-01-22 15:30:49 +01:00 by admin · 5 comments
Owner

Originally created by @romaricdrigon on GitHub (Oct 1, 2019).

Originally assigned to: @Ocramius on GitHub.

Bug Report

Q A
BC Break no
Version 2.6.*

Summary

Hello,

It is not possible to use an alias inside a DQL function, in a WHERE or HAVINg clause. SqlWalker crashes.

I will add a failing test scenario in a PR in a few minutes, I'm creating this issue to get a ticket number first.

Current behavior

Failure.
Example with a mainAccountEmail alias:

image

How to reproduce

This query will fail:
SELECT u.name AS foo FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE LOWER(foo) = '3'

Expected behavior

It should not crash, and generates a correct WHERE clause.
For the previous example:
SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE LOWER(name_0) = '3'

Originally created by @romaricdrigon on GitHub (Oct 1, 2019). Originally assigned to: @Ocramius on GitHub. ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | no | Version | 2.6.* #### Summary Hello, It is not possible to use an alias inside a DQL function, in a WHERE or HAVINg clause. SqlWalker crashes. *I will add a failing test scenario in a PR in a few minutes, I'm creating this issue to get a ticket number first.* #### Current behavior Failure. Example with a `mainAccountEmail` alias: ![image](https://user-images.githubusercontent.com/919405/65951846-25d16d80-e441-11e9-86ff-488ca9dfafc8.png) #### How to reproduce This query will fail: `SELECT u.name AS foo FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE LOWER(foo) = '3'` #### Expected behavior It should not crash, and generates a correct WHERE clause. For the previous example: `SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE LOWER(name_0) = '3'`
admin added the BugInvalid labels 2026-01-22 15:30:49 +01:00
admin closed this issue 2026-01-22 15:30:50 +01:00
Author
Owner

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

Closing here: this is correct behavior: WHERE LOWER(u.name) = '3' is correct/expected usage in DQL.

@Ocramius commented on GitHub (Oct 1, 2019): Closing here: this is correct behavior: `WHERE LOWER(u.name) = '3'` is correct/expected usage in DQL.
Author
Owner

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

@Ocramius I'm not sure to understand:

WHERE LOWER(u.name) = '3' is correct/expected usage in DQL.

It doesn't work at the moment. So incorrect/unexpected?

@romaricdrigon commented on GitHub (Oct 1, 2019): @Ocramius I'm not sure to understand: > WHERE LOWER(u.name) = '3' is correct/expected usage in DQL. It doesn't work at the moment. So incorrect/unexpected?
Author
Owner

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

Hmm, that doesn't work either? What's the exception in that case?

@Ocramius commented on GitHub (Oct 1, 2019): Hmm, that doesn't work either? What's the exception in that case?
Author
Owner

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

[Syntax Error] line 0, col 74: Error: Expected '.' or '(', got 'foo'

You can check https://github.com/doctrine/orm/pull/7847 for more details.

@romaricdrigon commented on GitHub (Oct 1, 2019): > [Syntax Error] line 0, col 74: Error: Expected '.' or '(', got 'foo' You can check https://github.com/doctrine/orm/pull/7847 for more details.
Author
Owner

@romaricdrigon commented on GitHub (Oct 4, 2019):

@Ocramius I believe this issue was dismissed too quickly, and PR #7847 too, since there are pending comments. Maybe you should reopen them?

@romaricdrigon commented on GitHub (Oct 4, 2019): @Ocramius I believe this issue was dismissed too quickly, and PR #7847 too, since there are pending comments. Maybe you should reopen them?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6318