Dev Helpers
← Back

Find gaps in identifiers

Find gaps in identifiers using SQLite.

Open this example in the interactive library

Source code

WITH ids(n) AS (VALUES(1),(2),(4)), gap AS (SELECT n,lead(n) OVER(ORDER BY n) AS next FROM ids) SELECT n+1 AS missing FROM gap WHERE next>n+1;

Sample output

[
  {
    "missing": 3
  }
]