org_unit proximity function (slow)
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 28 Jun 2005 20:53:22 +0000 (20:53 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 28 Jun 2005 20:53:22 +0000 (20:53 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@957 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/sql/Postgres/020.schema.functions.sql

index 89fdca3..059aa79 100644 (file)
@@ -76,3 +76,12 @@ CREATE OR REPLACE FUNCTION actor.org_unit_full_path ( INT ) RETURNS SETOF actor.
          FROM  actor.org_unit_descendants($1);
 ' LANGUAGE SQL STABLE;
 
+
+CREATE OR REPLACE FUNCTION actor.org_unit_proximity ( INT, INT ) RETURNS INT AS '
+       SELECT COUNT(id)::INT FROM (
+               select * from (SELECT id FROM  actor.org_unit_ancestors($1) UNION SELECT  id FROM  actor.org_unit_ancestors($2)) x
+                       EXCEPT
+               select * from (SELECT id FROM  actor.org_unit_ancestors($1) INTERSECT SELECT  id FROM  actor.org_unit_ancestors($2)) y) z;
+' LANGUAGE SQL STABLE;
+
+