Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [code]with recursive data(id, time, reply) as( values
- (1,1,1),
- (2,2,1),
- (3,3,1),
- (4,4,3),
- (5,5,3),
- (6,6,6),
- (7,7,4),
- (8,8,7),
- (9,9,8),
- (10,10,3)
- ), sorted as(
- select *, array[id] as path from data where id=1
- union
- select data.*, path||array[data.id] from sorted join data on data.reply=sorted.id and data.id!=sorted.id
- -- recursion guard to not hand on circular links
- where array_length(path,1)<100
- )
- select * from sorted order by path asc
Advertisement
Add Comment
Please, Sign In to add comment