I'm adding an 'index' column to a table in SQLite3 to allow the users to easily reorder the data, by renaming the old database and creating a new one in its place with the extra columns.
The problem I have is that I need to give each row a unique number in the 'index' column when I INSERT...SELECT the old values.
A search I did turned up a useful term in Oracle called ROWNUM, but SQLite3 doesn't have that. Is there something equivalent in SQLite?
sqlite is already adding rowid for you, no need to do the same twice. Note that rowid will be reused by the sqlite after a LOT of inserts, when old ones are deleted.
No SQLite doesn't have a direct equivalent to Oracle's ROWNUM.
If I understand your requirement correctly, you should be able to add a numbered column based on ordering of the old table this way:
The new table contains:
The
AUTOINCREMENT
does what its name suggests: each additional row has the previous' value incremented by 1.You can use one of the special row names
ROWID
,OID
or_ROWID_
to get the rowid of a column. See http://www.sqlite.org/lang_createtable.html#rowid for further details (and that the rows can be hidden by normal columns calledROWID
and so on).