I\'m getting this error using sqlite3 in django:
Exception Value: too many SQL variables
And I think the answer to it is this, from
Note: I am not Django expert
The problem is that in your query
vals = Company.objects.filter(id__in=comp_ids)...
you pass a bloated set of values and the underlaying engine cannot execute the query. Fortunately sqlalchemy, that you execute in that line, is lazy. You an execute a SELECT and then filter the entries "manually" without big performance penalties.
It would look more-less like that:
# here you should do a proper session.query(CompanyTable)
vals_all = Company.objects
vals_filtered = (item for item in vals_all if item.id in comp_ids)
vals_ordered = sorted(vals_filtered, key=attrgetter('name'))
vals_final = [(v.id, v.name) for v in vals_ordered]