mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Query builder yields invalid SQL with JOINED inheritance type on PostgreSQL #5554
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 @stesie on GitHub (May 22, 2017).
Originally assigned to: @Ocramius on GitHub.
Given a simple set of entities (adapted to a simpler domain here):
Postbelongs to anAuthorwhich derives fromUserPostandAuthoris not mapped (for reasons, as the real case is less simple)If I then instanciate and use a QueryBuilder like this:
it generates the following SQL
Which is valid for MySQL, however is not valid for PostgreSQL (tried with 9.6)
PostgreSQL seems to require an
ONclause with each and everyINNER JOIN(interestingly as opposed toLEFT JOIN). This is, the following query works with it:Pushing all conditions to
WHEREalso works on PostgreSQL:I haven't yet dug deeper, mainly as I never dived into Doctrine ORM code ... please let me know if you agree on this being a bug, ... I so far have no idea where it goes wrong, but let me know if I can support you, maybe by providing test code or start digging ...
@stesie commented on GitHub (May 23, 2017):
Well, so I had another look at this issue myself, and the SQL that probably should be generated is
... mind the parentheses around the CTI JOIN.
SqlWalker::walkJoinAssociationDeclarationalready has similar syntax around line 1043:If I apply this also to the code path through
walkJoinandwalkRangeVariableDeclarationlike this:... the sql statement from above is produced. And it works fine with PostgreSQL as well as MySQL.
Let me know if that's the way to go, then I'll happily provide a pull request...
@Deltachaos commented on GitHub (Nov 15, 2017):
This change is causing unnecessary bracets if there is no other JOIN in the brackets. This is invalid syntax (at least for SQL Server). Please have a look at the fix #6812