On Fri, Apr 10, 2009 at 5:23 AM, Andrew C <[email protected]> wrote:
>
> I would like to do aggregate calculations based on month for a
> datetime field.
This feature request has been made before; it's logged as ticket #10302.
> I am currently using the extra() function to format the date like:
>
> ...extra(select="strftime('column', '%m/%Y') as t").values
> ('t').annotate(SUM(foo))
>
> and it works great for sqlite3.
>
> In sqlite3 I can use strftime(), but that doesn't work with MySQL. In
> MySQL I can use date_format(), but that doesn't work with sqlite3.
>
> How can I rewrite this to work for both database types?
Your best bet will be to write a function that returns the different
function based on the value of settings.DATABASE_BACKEND. Ultimately,
when the feature is implemented, a function that does exactly this
will be put in to the database backend itself. Until then, you will
need to fake it.
Yours,
Russ Magee %-)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" 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-users?hl=en
-~----------~----~----~----~------~----~------~--~---