News for hackers. Stuff that matters.
Re:User-defined Order in SQL by etatoby on Saturday March 31, 2018 @11:54AM (#16723774)
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.

There are no comments on this comment yet.