Joel Jacobson <j...@gluefinance.com> writes:
> It's not possible to use a plain recursive query to do the trick (due
> to 'i' bidirectional dependencies and dependency loops).

Well I came up with that while working on some extension related fun
dependency problems, I guess it could help you:

~:5490=# WITH RECURSIVE depends AS (
 select 16385 as nsp, objid, refobjid, array[refobjid] as deps
   from pg_depend
  where refobjid = 16854 and deptype != 'p'
 UNION ALL
 select p.nsp, p.objid, d.refobjid, deps || d.refobjid
   from pg_depend d JOIN depends p ON d.objid = p.objid
  where d.deptype != 'p' and not d.refobjid = any(deps)
)
select * from depends;
  nsp  | objid | refobjid |        deps        
-------+-------+----------+--------------------
 16385 | 16851 |    16854 | {16854}
 16385 | 16852 |    16854 | {16854}
 16385 | 16853 |    16854 | {16854}
 16385 | 16851 |     2200 | {16854,2200}
 16385 | 16852 |     2200 | {16854,2200}
 16385 | 16852 |    16851 | {16854,16851}
 16385 | 16853 |     2200 | {16854,2200}
 16385 | 16852 |     2200 | {16854,16851,2200}
 16385 | 16852 |    16851 | {16854,2200,16851}
(9 rows)

Regards,
-- 
Dimitri Fontaine
http://2ndQuadrant.fr     PostgreSQL : Expertise, Formation et Support

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to