From: miker Date: Tue, 28 Jun 2005 20:53:22 +0000 (+0000) Subject: org_unit proximity function (slow) X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=53d288ce9dbef8a8143fc539fa2def369a4b122a;p=Evergreen.git org_unit proximity function (slow) git-svn-id: svn://svn.open-ils.org/ILS/trunk@957 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/sql/Postgres/020.schema.functions.sql b/Open-ILS/src/sql/Postgres/020.schema.functions.sql index 89fdca33ae..059aa79c22 100644 --- a/Open-ILS/src/sql/Postgres/020.schema.functions.sql +++ b/Open-ILS/src/sql/Postgres/020.schema.functions.sql @@ -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; + +