How to reorder rows in Postgresql I've got the following table  



And I have to change the order of the rows in an unpredictable way for example:  


Set the position of the row with id = 1 after the row with id = 3 and preserve the ordering of the other rows.
Add new row at position 3 right after row with id = 2.
Delete row from
position 4


What is the best solution for this problem?
There is no solution, because table rows in PostgreSQL don't have a fixed position in the table. Every UPDATE will change the position, and every new row will be inserted wherever there happens to be enough room.

Even if there are no modifications, sequential scans of the table don't necessarily start at the beginning.

The way to order rows is to use an appropriate ORDER BY clause with SELECT.