From: Jeff Davis Date: Wed, 29 Jul 2015 19:24:29 +0000 (-0700) Subject: LP1353643: fix CREATE FUNCTION order for new located URI scoping functions X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=c1e7253f41915dc7e63288e4b233a7aa620d6bc2;p=working%2FEvergreen.git LP1353643: fix CREATE FUNCTION order for new located URI scoping functions Signed-off-by: Jeff Davis --- diff --git a/Open-ILS/src/sql/Pg/020.schema.functions.sql b/Open-ILS/src/sql/Pg/020.schema.functions.sql index 059eec9f46..3af4e6ad34 100644 --- a/Open-ILS/src/sql/Pg/020.schema.functions.sql +++ b/Open-ILS/src/sql/Pg/020.schema.functions.sql @@ -249,6 +249,17 @@ CREATE OR REPLACE FUNCTION actor.org_unit_full_path ( INT, INT ) RETURNS SETOF a SELECT * FROM actor.org_unit_full_path((actor.org_unit_ancestor_at_depth($1, $2)).id) $$ LANGUAGE SQL STABLE ROWS 1; +CREATE OR REPLACE FUNCTION actor.org_unit_ancestor_fenced_path( INT, INT ) RETURNS SETOF actor.org_unit AS $$ + WITH RECURSIVE org_unit_ancestors_distance(id, distance) AS ( + SELECT $1, 0 + UNION + SELECT ou.parent_ou, ouad.distance+1 + FROM actor.org_unit ou JOIN org_unit_ancestors_distance ouad ON (ou.id = ouad.id) + WHERE ou.parent_ou IS NOT NULL + ) + SELECT ou.* FROM actor.org_unit ou JOIN org_unit_ancestors_distance ouad USING (id) ORDER BY ouad.distance DESC OFFSET $2; +$$ LANGUAGE SQL ROWS 1; + CREATE OR REPLACE FUNCTION actor.org_unit_full_path ( INT, INT, INT ) RETURNS SETOF actor.org_unit AS $$ SELECT * FROM actor.org_unit_ancestor_fenced_path($1, $2) @@ -275,17 +286,6 @@ CREATE OR REPLACE FUNCTION actor.org_unit_common_ancestors ( INT, INT ) RETURNS FROM actor.org_unit_ancestors($2); $$ LANGUAGE SQL STABLE ROWS 1; -CREATE OR REPLACE FUNCTION actor.org_unit_ancestor_fenced_path( INT, INT ) RETURNS SETOF actor.org_unit AS $$ - WITH RECURSIVE org_unit_ancestors_distance(id, distance) AS ( - SELECT $1, 0 - UNION - SELECT ou.parent_ou, ouad.distance+1 - FROM actor.org_unit ou JOIN org_unit_ancestors_distance ouad ON (ou.id = ouad.id) - WHERE ou.parent_ou IS NOT NULL - ) - SELECT ou.* FROM actor.org_unit ou JOIN org_unit_ancestors_distance ouad USING (id) ORDER BY ouad.distance DESC OFFSET $2; -$$ LANGUAGE SQL ROWS 1; - -- Given the IDs of two rows in actor.org_unit, *the second being an ancestor -- of the first*, return in array form the path from the ancestor to the -- descendant, with each point in the path being an org_unit ID. This is