LP1353643: fix CREATE FUNCTION order for new located URI scoping functions user/jeffdavis/lp1353643-fix-create-function-order-upstream
authorJeff Davis <jdavis@sitka.bclibraries.ca>
Wed, 29 Jul 2015 19:24:29 +0000 (12:24 -0700)
committerJeff Davis <jdavis@sitka.bclibraries.ca>
Wed, 29 Jul 2015 20:58:11 +0000 (13:58 -0700)
Signed-off-by: Jeff Davis <jdavis@sitka.bclibraries.ca>
Open-ILS/src/sql/Pg/020.schema.functions.sql

index 059eec9..3af4e6a 100644 (file)
@@ -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