With pure MySQL, I can do something like:
SET @weight:=0;
UPDATE mymodule_table
SET mymodule_weight=@weight:=@weight+1
ORDER BY mymodule_weight, mymodule_id;
Is there a Drupal way to achieve similar result? Can I avoid calls to db_query
and push it with db_update
or db_merge
?
MySQL solution adapted from this answer.