android sqlite3 table vacuum not working

577 views Asked by At

I need to reorder the rowid sequentially after deleting some rows. Vacuum on table seems to be a good fit for the situation but for some reasons its not reordering the rowid.

sqlite> .schema inboxmessages 
CREATE TABLE InboxMessages(id text not null, title text not null, text text not null, senders_username text not null, created_at text not null, sender_image text not null, read text not null, Unique(id));

sqlite> select rowid, id from inboxmessages limit 5;
1|746915
3|746540
4|746195
5|745403
6|745371
sqlite> vacuum inboxmessages;
sqlite> select rowid, id from inboxmessages;
1|746915
3|746540
4|746195
5|745403
6|745371

whats wrong ?

1

There are 1 answers

0
CL. On BEST ANSWER

VACUUM is not guaranteed to reorder rowid values, and if there is some INTEGER PRIMARY KEY column, it never will.

If you want to have specific values for your rowids, you have to set them manually.

Please note that in most cases, it is a better idea to just leave gaps in the rowid sequence.