Hello,

I’d like to execute the following code:

Booking.objects.filter(start_ts__isnull = False, end_ts__isnull =
False).extra(select = {'amount': "strftime('%s', end_ts) - strftime('%s',
start_ts)"})

However, in the shell, I get the following error:

Traceback (most recent call last): File "<console>", line 1, in <module>
File
"/home/polesz/Projects/duckbook/venv/lib/python3.4/site-packages/django/db/models/query.py",
line 835, in extra clone.query.add_extra(select, select_params, where,
params, tables, order_by) File
"/home/polesz/Projects/duckbook/venv/lib/python3.4/site-packages/django/db/models/sql/query.py",
line 1744, in add_extra entry_params.append(next(param_iter)) StopIteration

I have tried doubling the percent signs (%%s) and escaping them with a
backslash (\%s), but neither helped. I also looked at this answer
<http://stackoverflow.com/a/18143147/1305139>[1], but that solution doesn’t
work with QuerySet.extra() (or I just miss the point).

What is the correct way to solve this?

I also tried to use select_params like this:

Booking.objects.filter(start_ts__isnull = False, end_ts__isnull =
False).extra(select = {'amount': "strftime('%s', end_ts) - strftime(%s,
start_ts)"}, select_params = ['%s', '%s'])

but regardless the usage of quote signs, the resulting query has \'%s\',
which gives an SQL error, of course.

Best,
Gergely

[1] http://stackoverflow.com/a/18143147/1305139

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACczBULm5dPUvYc4Me-yNqsC%3DgS1grpa4Q%2BMVtPnHVEOCrzfcQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to