sql update - How to temporarily break column uniqueness in SQLite? -


i've got simple table:

create table checkliststep (     checklist integer references checklist (id),      id        integer primary key autoincrement,      stepindex integer not null,      name      varchar not null,      unique (checklist, stepindex)); 

now want exchange 2 items' indexes. doing i'm breaking temporarily uniqueness of pair (checklist, stepindex). hoped, can in transaction, such after committing, constraints kept, doesn't work:

begin transaction; update checkliststep set stepindex = 0 id = 6; update checkliststep set stepindex = 1 id = 5; commit transaction; 

causes:

unique constraint failed: checkliststep.checklist, checkliststep.stepindex 

how write such update?

sqlite not have deferred unique constraints.

the pragma writable_schema dirty trick not work here because internal index corrupted if changed table without updating index.

the way use temporary value guaranteed unused:

begin; update checkliststep set stepindex = -99999999 id = 6; update checkliststep set stepindex = 1 id = 5; update checkliststep set stepindex = 0 id = 6; commit; 

Comments

Popular posts from this blog

'hasOwnProperty' in javascript -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to provide dependency injections in Eclipse RCP 3.x? -