Refer to Identifying missing sequences in SQLite table for the original problem and solution.
The following code correctly identifies missing sequences, however, its starting point is the lowest number in the sequence based on the data in the table. So for example, if the sequence is supposed to start at 1, but the first sequence in the data begins with 5, then 1..4 are not included in the result.
Any tips on how to test using a predefined start sequence?
SELECT dir, start, stop
FROM (
SELECT m.id + 1 start,
(SELECT MIN(id) - 1 FROM sequence x WHERE x.__dirpath = m.__dirpath AND x.id > m.id) stop,
m.__dirpath dir
FROM sequence m LEFT JOIN sequence r
ON m.__dirpath = r.__dirpath AND m.id = r.id - 1
WHERE r.id IS NULL
)
WHERE stop IS NOT NULL
ORDER BY dir, start, stop;