sqlite ON CONFLICT difference between ABORT and FAIL -


from http://www.sqlite.org/lang_conflict.html

abort when applicable constraint violation occurs, abort resolution algorithm aborts current sql statement sqlite_constrait error , backs out changes made current sql statement; changes caused prior sql statements within same transaction preserved , transaction remains active. default behavior , behavior proscribed sql standard.

fail when applicable constraint violation occurs, fail resolution algorithm aborts current sql statement sqlite_constraint error. fail resolution not out prior changes of sql statement failed nor end transaction. example, if update statement encountered constraint violation on 100th row attempts update, first 99 row changes preserved changes rows 100 , beyond never occur.

both preserve changes made before statement caused constraint violation , not end transaction. so, suppose difference fail resolution not let further changes made, while abort conflicting statement. did right?

the answer simple: fail not rollback changes done current statement.

consider 2 tables:

create table if not exists constfail (num unique on conflict fail); create table if not exists constabort (num unique on conflict abort); insert constfail values (1),(3),(4),(5),(6),(7),(8),(9),(10); insert constabort values (1),(3),(4),(5),(6),(7),(8),(9),(10); 

the statement

update constabort set num=num+1 num<10 

will fail , change nothing. satement

update constfail set num=num+1 num<10 

will update first row, fail , leave 1 row updated, new values 2, 3, 4, 5, 6, 7, 8, 9, 10


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -