#11916: Extra params + aggregation creates incorrect SQL.
---------------------------------------------------+------------------------
Reporter: [email protected] | Owner: nobody
Status: reopened | Milestone: 1.2
Component: Database layer (models, ORM) | Version: 1.1
Resolution: | Keywords:
Stage: Accepted | Has_patch: 1
Needs_docs: 0 | Needs_tests: 1
Needs_better_patch: 0 |
---------------------------------------------------+------------------------
Comment (by anentropic):
I ran into this bug too, the whole sub-select statement of my extra()
clause got copied into the group by portion of the query, when just the
key name would be sufficient. Don't know if there's some case where you'd
want that, but this is a +1 on '''paluh''''s patch - works for me!
{{{
qs.annotate(stock=Sum('variants__stock')).filter(Q(stock__gt=0)).extra(
select={
'op_option_group_id': '''
SELECT op.option_group_id FROM
store_optionedproduct op, store_product WHERE
op.product_ptr_id=store_product.id LIMIT 1
'''
}
)
}}}
{{{
SELECT
(SELECT op.option_group_id FROM store_optionedproduct op,
store_product WHERE op.product_ptr_id=store_product.id) AS
`op_option_group_id`
FROM `store_product`
LEFT OUTER JOIN `store_productvariant` ON
(`store_product`.`id` = `store_productvariant`.`product_id`)
WHERE (`store_product`.`status` IN (1))
GROUP BY `store_product`.`id`,
--> SELECT op.option_group_id FROM store_optionedproduct op,
store_product WHERE op.product_ptr_id=store_product.id
HAVING SUM(`store_productvariant`.`stock`) > 0 ORDER BY NULL
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/11916#comment:6>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.