update query set with a limit

590 views
Skip to first unread message

Harley Bussell

unread,
Feb 27, 2010, 11:07:19 PM2/27/10
to Django users
Hi, id like to know if any one has found a work around to use limits
when updating a query set.

I'm trying to lock a number of the oldest rows in a table.
update job set lock='lockid' where lock ='' order by created limit 10;

Ideally id like to do something like this:
Job.objects.filter(lock='').order_by('created').update(lock='lockid')
[0:10]

Now i'm just using raw sql to lock which is fine but it would be great
if there was a way to do it with the orm.

Appreciate any advice
Thanks

James Bennett

unread,
Feb 27, 2010, 11:21:18 PM2/27/10
to django...@googlegroups.com
On Sat, Feb 27, 2010 at 10:07 PM, Harley Bussell <mod...@gmail.com> wrote:
> Hi, id like to know if any one has found a work around to use limits
> when updating a query set.

This is unlikely to be supported by Django; "UPDATE ... LIMIT" is
non-standard, non-portable and MySQL is the only DB supporting it out
of the box.


--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

Reply all
Reply to author
Forward
0 new messages