Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
As described in the hijack of #1054168-2: EntityFieldQuery fails for entities that have no bundle if you have something like
SELECT column + 1 AS calculated_column
HAVING calculated_column > 1
convert this into DBTNG and make it a countQuery then it removes the column + 1 AS calculated_column expression and replaces with COUNT(*) which fails the HAVING.
Comment | File | Size | Author |
---|---|---|---|
#15 | d7-1258000-14.patch | 4.79 KB | xjm |
#10 | 1258000_POST-APOCALYPSE.patch | 4.83 KB | xjm |
#7 | 1258000_7.patch | 4.79 KB | chx |
#4 | 1258000_4.patch | 4.91 KB | chx |
#2 | 1258000-2.patch | 2.3 KB | bfroehle |
Comments
Comment #1
chx CreditAttribution: chx commentedTest, fails.
Comment #2
bfroehle CreditAttribution: bfroehle commentedIs this sort of approach what we are looking for?
Comment #3
chx CreditAttribution: chx commentedThanks for jumping on the issue so quick!
HAVING foo = 1 AND ( bar = 1 OR bar > 3)
will break (Edit: for bar). I think you need to refactor the having handling to collect fields. Edit: and even that might not be enough because if you have several levels of DatabaseConditions then havingCondition will only see the top ones. :/Comment #4
chx CreditAttribution: chx commentedI needed to merge #1196292: Allow Pager count queries to utilise GROUP BY into this one to make the test pass. We dont remove any expression if there is HAVING.
Comment #5
Damien Tournoud CreditAttribution: Damien Tournoud commentedI am not sure the original query is valid in the first place. In strict SQL, WHERE and GROUP BY can only contain references to columns, not to aliases. It is likely the case for HAVING too.
Comment #6
chx CreditAttribution: chx commentedSure. The having methods fixes are still valid even if the countQuery isn't.
Comment #7
chx CreditAttribution: chx commentedI studied http://www.postgresql.org/docs/8.1/static/tutorial-agg.html and http://www.postgresql.org/docs/9.0/static/sql-select.html#SQL-HAVING and I think that you can run HAVING on an expression provided the column (or the expression itself?? MySQL and PostgreSQL seems to disagree on that) is selected.
Comment #8
xjmTracking.
Comment #9
catchTagging for backport.
Comment #10
xjmRerolled for
core/
.Comment #13
Crell CreditAttribution: Crell commentedLooking at the patch itself, it's a major "duh". :-) (chx talked to me about this a while back; it just fell off my radar.)
Comment #14
catchLooks great, don't see anything to complain about. Committed to 8.x, moving back to 7.x for which this will need a re-roll.
Comment #15
xjmNothing particular to D8 so it's a straight reroll.
Comment #16
Dries CreditAttribution: Dries commentedCommitted to 7.x. Thanks!
Comment #17
aspilicious CreditAttribution: aspilicious commented:)
Comment #18.0
(not verified) CreditAttribution: commentedchanged to #1054168-2 instead of #1054168:2