CREATE PROCEDURE move_rows ( IN position_move_from INT,
IN position_move_to INT )
UPDATE test
SET pos = CASE WHEN id = position_move_to
THEN position_move_from
ELSE pos + SIGN(position_move_to - position_move_from)
END
WHERE id BETWEEN LEAST(position_move_from, position_move_to)
AND GREATEST(position_move_from, position_move_to)
ORDER BY id = position_move_to;