create table tbl (id int primary key);
insert into tbl values (3),(4),(5);
select count(*) from (
select id - (lag(id) over (order by id)) diff from tbl
) t where diff is not null and diff <> 1;
insert into tbl values (7),(8);
select count(*) from (
select id - (lag(id) over (order by id)) diff from tbl
) t where diff is not null and diff <> 1;