0

I'm trying to add an extra field to a select statement in django, In which I want to use a varying format string.

The following results in:
Incorrect number of bindings supplied. The current statement uses 3, and there are 4 supplied.

select=SortedDict([(
    "groupkey", 
    "strftime('%s', datetime(time, 'utc'),'localtime')")]),
select_params=(
    "%m"
)

This way I get:
unsupported format character 'm' (0x6d) at index 19 when using %m as a format string. It seems to work when using %%m as a format string but I don't consider this as a nice solution.

select={
    "groupkey":"strftime('" + self.__formatstring + "', datetime(time, 'utc'),'localtime')"
})

Thank you!

Simbi
  • 992
  • 3
  • 13
  • 29
  • 1
    What exactly are you trying to achieve here? – Thomas Orozco Jan 01 '13 at 14:54
  • I want to group the values in the table either by minute, hour, day, month or year. Using plain SQL I did this by using the sqlite built in strftime function. (e.g. GROUP BY strftime("%m", time) would group by month). For some reason the "%" symbols seem to screw up the django orm module, and I'd have to use "%%m" (which I don't want to do) – Simbi Jan 01 '13 at 15:16
  • 1
    Have a look at: http://stackoverflow.com/questions/3543379/django-annotate-groupings-by-month – Thomas Orozco Jan 01 '13 at 15:40

0 Answers0