4 ms·
This is just off the top of my head, but to move an item from position P to Q, you would do something like this: update items set pos = case wh
by etatoby 9y ago
This is just off the top of my head, but to move an item from position P to Q, you would do something like this:
update items
set pos = case
when pos = P then Q
when P < Q and pos between P and Q then pos - 1
when Q < P and pos between Q and P then pos + 1
else pos
end
Plus a where clause to limit the shuffling to the actual list being reordered, since you would keep all users' lists in the same table.