From 53d288ce9dbef8a8143fc539fa2def369a4b122a Mon Sep 17 00:00:00 2001 From: miker Date: Tue, 28 Jun 2005 20:53:22 +0000 Subject: [PATCH] org_unit proximity function (slow) 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 | 9 +++++++++ 1 file changed, 9 insertions(+) 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; + + -- 2.11.0