Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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)


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'




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: