SQLite Forum

table locked when dropping a temp table
Login
Though, you could of course, do:

```
INSERT INTO variables
SELECT * FROM variables WHERE orden >= 6 ORDER BY orden DESC
ON CONFLICT(orden) DO UPDATE SET orden = excluded.orden + 1;
```

as in

```
sqlite> create table x(id integer primary key, orden integer not null unique, y not null);
sqlite> insert into x (orden, y) select value, randomv(100) from wholenumber where value between 1 and 10;
sqlite> select * from x;
┌────┬───────┬────┐
│ id │ orden │ y  │
├────┼───────┼────┤
│ 1  │ 1     │ 13 │
│ 2  │ 2     │ 96 │
│ 3  │ 3     │ 84 │
│ 4  │ 4     │ 95 │
│ 5  │ 5     │ 36 │
│ 6  │ 6     │ 89 │
│ 7  │ 7     │ 39 │
│ 8  │ 8     │ 94 │
│ 9  │ 9     │ 32 │
│ 10 │ 10    │ 61 │
└────┴───────┴────┘
sqlite> insert into x
   ...> select * from x where orden >= 5 order by orden desc
   ...> on conflict (orden) do update set orden = excluded.orden+1;
sqlite> select * from x;
┌────┬───────┬────┐
│ id │ orden │ y  │
├────┼───────┼────┤
│ 1  │ 1     │ 13 │
│ 2  │ 2     │ 96 │
│ 3  │ 3     │ 84 │
│ 4  │ 4     │ 95 │
│ 5  │ 6     │ 36 │
│ 6  │ 7     │ 89 │
│ 7  │ 8     │ 39 │
│ 8  │ 9     │ 94 │
│ 9  │ 10    │ 32 │
│ 10 │ 11    │ 61 │
└────┴───────┴────┘
```