create table if not exists t (id int);
delete from t;
insert into t values (1), (2), (3), (4), (6), (7), (9);
with q as (select id from t order by id desc limit 1),
s as (select g as id from q, generate_series(1,
q.id) as g),
e as (
select id from s
except
select id from t
)
select id from e
order by id
limit 1