﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
21182	Extra Column in Group By When Using date_trunc	anonymous	nobody	"I'm trying to basically sum the amount column of a bunch of financial transactions per-month by category.  I seem to have gotten 90% of the way there with the ORM, but it looks like it is getting confused by my use of date_trunc.  In the Group By, all I want is category_id and month (the date_trunc result), yet I also get the raw date column as well.

Here's the code I've put together for the ORM so far:
{{{
span=""month""
truncate_date = django.db.connection.ops.date_trunc_sql(span, ""date"")
print Transaction.objects.extra({span: truncate_date}).values(""category"", span).annotate(total=Sum(""amount"")).query
}}}

This results in:
{{{
SELECT (django_date_trunc('month', date)) AS ""month"", ""finance_transaction"".""category_id"", SUM(""finance_transaction"".""amount"") AS ""total"" FROM ""finance_transaction"" GROUP BY ""finance_transaction"".""category_id"", ""finance_transaction"".""date"", (django_date_trunc('month', date)) ORDER BY ""finance_transaction"".""date"" DESC
}}}"	Bug	closed	Database layer (models, ORM)	1.5	Normal	needsinfo			Unreviewed	0	0	0	0	0	0
