Re:Data denormalization is broken
by fdgdasfadsf on Saturday October 01, 2016 @04:40AM
(#12617062)
This is what the Django ORM does when used with some degree of care.
[ Parent
| on HN ]
Re:Data denormalization is broken
by icebraining on Saturday October 01, 2016 @04:49AM
(#12617082)
I 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?There 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)
Re:Data denormalization is broken
by combatentropy on Saturday October 01, 2016 @01:04PM
(#12618750)
To 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'