There is a table with 200 records and one of the fields is responsible for indicating the order that these data are displayed (0, 1, 2, 3, 4, 5, ...). I need to rearrange this data, pick up the record from position 167 and put it in position 3, and obviously what was in position 3 will go to position 4, and 4 to 5, and so on. The problem is that I will have to change the "position" field of the 164 records that had the modified position. Is there any efficient way to do this? Or do I have to loop through each record individually? What if you have to reorganize more than one record?
Note: I'm working with Python, PostgreSQL and Django