3 INSERT INTO config.upgrade_log (version) VALUES ('0445'); -- miker
5 CREATE OR REPLACE FUNCTION actor.org_unit_descendants( INT, INT ) RETURNS SETOF actor.org_unit AS $$
6 WITH RECURSIVE descendant_depth AS (
10 FROM actor.org_unit ou
11 JOIN actor.org_unit_type out ON (out.id = ou.ou_type)
12 JOIN anscestor_depth ad ON (ad.id = ou.id)
18 FROM actor.org_unit ou
19 JOIN actor.org_unit_type out ON (out.id = ou.ou_type)
20 JOIN descendant_depth ot ON (ot.id = ou.parent_ou)
21 ), anscestor_depth AS (
25 FROM actor.org_unit ou
26 JOIN actor.org_unit_type out ON (out.id = ou.ou_type)
32 FROM actor.org_unit ou
33 JOIN actor.org_unit_type out ON (out.id = ou.ou_type)
34 JOIN anscestor_depth ot ON (ot.parent_ou = ou.id)
35 ) SELECT ou.* FROM actor.org_unit ou JOIN descendant_depth USING (id);
38 CREATE OR REPLACE FUNCTION actor.org_unit_descendants( INT ) RETURNS SETOF actor.org_unit AS $$
39 WITH RECURSIVE descendant_depth AS (
43 FROM actor.org_unit ou
44 JOIN actor.org_unit_type out ON (out.id = ou.ou_type)
50 FROM actor.org_unit ou
51 JOIN actor.org_unit_type out ON (out.id = ou.ou_type)
52 JOIN descendant_depth ot ON (ot.id = ou.parent_ou)
53 ) SELECT ou.* FROM actor.org_unit ou JOIN descendant_depth USING (id);
56 CREATE OR REPLACE FUNCTION actor.org_unit_ancestors( INT ) RETURNS SETOF actor.org_unit AS $$
57 WITH RECURSIVE anscestor_depth AS (
60 FROM actor.org_unit ou
65 FROM actor.org_unit ou
66 JOIN anscestor_depth ot ON (ot.parent_ou = ou.id)
67 ) SELECT ou.* FROM actor.org_unit ou JOIN anscestor_depth USING (id);