Allow field aliases in subselects #4922

Open
opened 2026-01-22 14:52:03 +01:00 by admin · 1 comment
Owner

Originally created by @kitsunet on GitHub (Dec 8, 2015).

In a DQL Subselect you cannot give the selected field an alias to reference to it because the Parser uses SimpleSelectClause (fine as you want to only select one field) but that in turn uses simpleSelectExpression instead of just selectExpression to parse the SELECT part of the subquery. Unfortunately does simpleSelectExpression not properly take aliases into account.

The following Query therefore becomes impossible:

SELECT n FROM Nodes WHERE n.id IN (SELECT SUBSTRING(d.idAndStuff, 4, 36) AS node_id FROM Dim WHERE node_id LIKE ....) because without the alias "node_id" I cannot reference this derived field.

Originally created by @kitsunet on GitHub (Dec 8, 2015). In a DQL Subselect you cannot give the selected field an alias to reference to it because the Parser uses `SimpleSelectClause` (fine as you want to only select one field) but that in turn uses `simpleSelectExpression` instead of just `selectExpression` to parse the SELECT part of the subquery. Unfortunately does `simpleSelectExpression` not properly take aliases into account. The following Query therefore becomes impossible: `SELECT n FROM Nodes WHERE n.id IN (SELECT SUBSTRING(d.idAndStuff, 4, 36) AS node_id FROM Dim WHERE node_id LIKE ....)` because without the alias "node_id" I cannot reference this derived field.
Author
Owner

@kitsunet commented on GitHub (Dec 8, 2015):

A quick test with using selectExpression instead of simpleSelectExpression makes that work, but I don't know if that has unintented side effects.

@kitsunet commented on GitHub (Dec 8, 2015): A quick test with using `selectExpression` instead of `simpleSelectExpression` makes that work, but I don't know if that has unintented side effects.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4922