AUTOMATIC1111

Untitled

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