Skip to content

Instantly share code, notes, and snippets.

@shortcircuit3
Created April 11, 2020 20:04
Show Gist options
  • Save shortcircuit3/3e9d2a3c9f217ef05105061e2038307a to your computer and use it in GitHub Desktop.
Save shortcircuit3/3e9d2a3c9f217ef05105061e2038307a to your computer and use it in GitHub Desktop.
select "sequence".id + 1 as start, min(fr.id) - 1 as stop
from "sequence"
left outer join sequence as r on "sequence".id = r.id - 1
left outer join sequence as fr on "sequence".id < fr.id
where r.id is null and fr.id is not null
group by "sequence".id, r.id;
@shortcircuit3
Copy link
Author

select "blocks".number + 1 as start, min(fr.number) - 1 as stop
from "blocks"
    left outer join blocks as r on "blocks".number = r.number - 1
    left outer join blocks as fr on "blocks".number < fr.number
where r.number is null and fr.number is not null
group by "blocks".number, r.number;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment