Tag Info

New answers tagged


The problem was caused by multiplication in the recursive calls. When I deleted one of them, the problem was solved: WITH RECURSIVE najdi_tot(sj) AS ( SELECT nad FROM s_vztah WHERE pod=581 UNION SELECT pod FROM s_vztah WHERE nad=581 UNION SELECT sv.nad FROM najdi_tot n, s_vztah sv WHERE sv.pod = n.sj ) SELECT array_agg(sj) ...


A recursive CTE seems the way to go. Assuming your path has no cycles. Else it needs more work to detect cycles. The array solution below can readily be adapted. Test setup Building on this simplified layout: CREATE TABLE t1 (t1_id int, objid text); INSERT INTO t1 VALUES (1,'aaa') ,(2,'bbb') ,(3,'ccc') ,(4,'ddd') ,(5,'eee') ,(6,'fff') ,(7,'ggg') ...

Top 50 recent answers are included