Skip to content

Instantly share code, notes, and snippets.

@azenla
Created October 10, 2017 18:30
Show Gist options
  • Save azenla/c9add234f8e659130622bf968b535cbf to your computer and use it in GitHub Desktop.
Save azenla/c9add234f8e659130622bf968b535cbf to your computer and use it in GitHub Desktop.
with recursive rel_tree as (
select "hash", "parent", 1 as level, cast(array["hash"] AS varchar(512)[]) as path_info
from "git.commits"
where "parent" is null
union all
select c.hash, c.parent, p.level + 1, cast((p.path_info || c.hash) AS varchar(512)[])
from "git.commits" c
join rel_tree p on c.parent = p.hash
)
select "rel_tree"."hash", "git.commits"."commit_time", "git.commits"."message" from rel_tree inner join "git.commits" on "git.commits"."hash"="rel_tree"."hash" order by array_length(path_info, 1) desc limit 5;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment