3 ms·
This is what the Django ORM does when used with some degree of care.
by fdgdasfadsf 10y ago
This is what the Django ORM does when used with some degree of care.
- icebraining 10y agoI know it uses lazy results, but can you actually loop over the results without triggering a query? Could you write something like: records = ORM.search(type='X') for record in records: record.a = record.b + 30 and only trigger a single UPDATE query?
- collyw 10y agoThere is an update method that can be used with F expressions to achieve this. This is the example in their docs: Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
- combatentropy 10y agoTo write it in pure SQL would ensure the single query you're looking for and be less to type: update records set a = b + 30 where type = 'X'