3 SELECT evergreen.upgrade_deps_block_check('0768', :eg_version);
5 CREATE OR REPLACE FUNCTION evergreen.rank_ou(lib INT, search_lib INT, pref_lib INT DEFAULT NULL)
9 -- lib matches search_lib
10 (SELECT CASE WHEN $1 = $2 THEN -20000 END),
12 -- lib matches pref_lib
13 (SELECT CASE WHEN $1 = $3 THEN -10000 END),
16 -- pref_lib is a child of search_lib and lib is a child of pref lib.
17 (SELECT distance - 5000
18 FROM actor.org_unit_descendants_distance($3)
19 WHERE id = $1 AND $3 IN (
20 SELECT id FROM actor.org_unit_descendants($2))),
22 -- lib is a child of search_lib
23 (SELECT distance FROM actor.org_unit_descendants_distance($2) WHERE id = $1),
25 -- all others pay cash
28 $$ LANGUAGE SQL STABLE;