Avoiding SQLite update+annotations "only a single result allowed for a SELECT that is part of an expression"
|Reported by:||jonash||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.4|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
When executing something like
Foo.objects.annotate(bar_count=Count('bars')) \ .update(spam=42)
SQLite throws an only a single result allowed for a SELECT that is part of an expression error.
This can be worked around using .values('id'):
Foo.objects.annotate(bar_count=Count('bars')) \ .values('id') \ .update(spam=42)
Looks like SQLite can't cope with multiple fields in the SELECT clause, so I suggest not SELECTing all the fields if we don't need them anyways (as in this case).
Change History (7)
comment:1 Changed 4 years ago by aaugustin
- Component changed from Database layer (models, ORM) to ORM aggregation
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
- Type changed from Uncategorized to Bug
Changed 4 years ago by akaariai
comment:3 Changed 3 years ago by akaariai
- Component changed from ORM aggregation to Database layer (models, ORM)