﻿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
11117	placeholder confusion when using aggregated query with extra	slide21@…	nobody	"Let's assume something like this:

{{{
Book.objects.extra(select={'date': ""DATE_FORMAT(timestamp, '%s')""}, select_params=('%%H',), where=[""DATE_FORMAT(timestamp, '%%H:%%i') > '%s'""], params=['22:00']).values('date').annotate(cnt=Count('id'))
}}}

----

the resulting sql query is:

{{{
SELECT DATE_FORMAT(timestamp, '%H') AS `date`, COUNT(id) AS `cnt` FROM `books` WHERE DATE_FORMAT(timestamp, '%H:%i') > '%H' GROUP BY DATE_FORMAT(timestamp, '22:00') ORDER BY timestamp ASC
}}}

----
the placeholder values '%H' and '22:00' are interchanged, which is obviously a result of using the GROUP BY here on a user-defined variable with placeholder (--> 'date')

.query.as_sql() gives something like

{{{
(u""SELECT DATE_FORMAT(timestamp, '%s') AS `date`, COUNT(id) AS `cnt` FROM `books` WHERE DATE_FORMAT(timestamp, '%H:%i') > '%s' GROUP BY DATE_FORMAT(timestamp, '%s') ORDER BY timestamp ASC"", (u'%H', u'%H', u'22:00'))
}}}




"		closed	Database layer (models, ORM)	1.0		duplicate			Unreviewed	0	0	0	0	0	0
