Seems to work just fine if foreign_keys are disabled, recursive triggers are disabled, and the recursive recursiveness in your trigger is fixed (by removing the superfluous update). One would presume that the reason you want to have all these things is so that you can have the database engine enforce integrity and do things for you. Thus you should concentrate on fixing your schema and triggers first since your script does not run at all if foreign key enforcement is enabled. And of course it never updates anything because you are recursively updating the same table you are updating in the trigger that runs before the update in which you are performing and update which would ABORT but rather otherwise does a rollback because it is recursing recursively and you have overridden the CONFLICT resolution method in the update that runs within the before update trigger. Updating the record which will be updated in a before update trigger causes either infinite recursion or "undefined behaviour".