how to re-index (number) sorted sqlite table

sql, sqlite

Solution

How about this?

 UPDATE todo SET id = rowid

Problem

for example I've got nodes with indexes ``` 1 2 7 8 ``` I need to change indexes to ``` 1 2 3 4 ``` I can ``` UPDATE TODO SET id = id + 1000000000 UPDATE TODO SET id = id - (1000000000 + 1) ``` (tricky because id must be unique) to shift all the indexes and make 0 1 6 7 but I need to make relation, need to make first index shift to 0, and other index shift to previous index. There is no stored procedures in sqlite so I'm confised about How can I make such relation without variables? every logics tips are welcome.

Original source