mirror of
https://github.com/doctrine/orm.git
synced 2026-04-29 09:23:20 +02:00
DDC-2917: Inheritance using joins generates invalid SQL when used in SELECT queries with GROUP BY on Postgresql #3633
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Jan 15, 2014).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user tom.pryor:
Say you have an entity with InheritanceType("JOINED"), some child entities defined in the DiscriminatorMap which include additional columns and are using PostgreSQL then try and execute a DQL query as below:
Note: This is simplified for ease of reproduction, obviously the GROUP BY is pointless but in my actual query, which is significantly larger, the GROUP BY is actually useful.
PostgreSQL will give the following error:
Where f2_ is an alias in the actual SQL for one of the child entities.
This is because the SELECT in the actual SQL attempts to fetch the columns from the joined child entities but does not include them in the GROUP BY clause.
Bad SQL generated:
The SQL should be:
N.b later versions of PostgreSQL don't require the GROUP BY on all the columns, just the primary key. Therefore the following would be sufficient:
@doctrinebot commented on GitHub (Aug 24, 2015):
Comment created by ambroisemaupate:
Same issue for me:
The following code works for mysql and crash on pgsql.
Seen on https://github.com/roadiz/roadiz/issues/169
@dbykadorov commented on GitHub (Jul 27, 2016):
Hello! Does anybody knows workarround for this issue?