I have a table created with
CREATE TABLE `tests` (`num` INTEGER UNIQUE, value VARCHAR(255))
and I add two rows to it with:
INSERT INTO `tests` VALUES(0, "a")
INSERT INTO `tests` VALUES(1, "b")
My goal is now to insert a row with num
= 0, but to be able to do that, I need to shift up the index on those two rows.
When I execute:
UPDATE `tests` SET `num` = `num` + 1 WHERE `num` >= 0
I get the error:
could not execute statement due to a constaint failure (19 constraint failed)
My guess is that it is incrementing each row, and when it goes to increment the first one by setting it to 1
, there is already a row with the num
of 1
, thus failing.
In standard code this would be solved by iterating backwards over the collection, is there any way to do that in Sqlite? Is there a different way to go about this?