Dear SQLiters,

I would like to update a column declared as INTEGER PRIMARY KEY. This column is 
parent to a column of another table:

table1 ( t INTEGER PRIMARY KEY NOT NULL);

table2 (t INTEGER PRIMARY KEY NOT NULL REFERENCES table1(t) ON DELETE CASCADE 
ON UPDATE CASCADE);

I keep PRAGMA foreign_keys = 'yes'; so that when I update table1, table2 also 
gets updated. Values in column t are positive and negative integers. When I try 
to add a constant I get constraint violation:

UPDATE table1 SET t =  t + 8000;


Error: UNIQUE constraint failed: table1.t


But, if I subtract a positive constant, the update succeeds.


I understand that as I add or subtract a constant, numbers become those that 
already exist. However, by the end of the UPDATE, all numbers will still be 
unique.


It looks like the UPDATE happens in some order and if I can force the order of 
update depending on the sign of the constant, it will always succeed as I need. 
But UPDATE has no ordering mechanism because it makes no sense to have one.


Does it mean I am doing it incorrectly? How to do I update? Bracketing with 
BEGIN .. COMMIT did not help.



Thank you,


Roman

_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to