From: Doug Kyle Date: Fri, 11 Apr 2014 14:46:31 +0000 (-0400) Subject: Better loc or group function X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=c7c060cda1fe638f5405a333e6ca877f45ee2dd1;p=working%2FEvergreen.git Better loc or group function Signed-off-by: Doug Kyle --- diff --git a/Open-ILS/src/sql/Pg/smart_float.sql b/Open-ILS/src/sql/Pg/smart_float.sql index 32fcaf4e0a..eaa08d3fa6 100644 --- a/Open-ILS/src/sql/Pg/smart_float.sql +++ b/Open-ILS/src/sql/Pg/smart_float.sql @@ -246,25 +246,19 @@ BEGIN END; $function$; --- !!! smart_float.loc_or_locgroup !!! -CREATE OR REPLACE FUNCTION smart_float.loc_or_locgroup(loc integer) - RETURNS integer +-- !!! smart_float.loc_or_group !!! +CREATE OR REPLACE FUNCTION smart_float.loc_or_group(loc integer) RETURNS integer LANGUAGE plpgsql - STABLE COST 10 AS $function$ DECLARE - found_loc BOOLEAN; - loc_group INT; + STABLE COST 10 AS $function$ DECLARE + loc_group INT := 0; BEGIN - SELECT INTO found_loc loc IN (select shelf_location from config.smart_float where shelf_is_group is FALSE group by 1); - IF found_loc IS FALSE THEN - SELECT INTO loc_group lgroup from asset.copy_location_group_map where location = loc - and lgroup in (select shelf_location from config.smart_float where shelf_is_group is TRUE group by 1); - IF FOUND THEN - RETURN loc_group; - END IF; + select into loc_group shelf_location from config.smart_float where shelf_is_group is true and shelf_location in (select lgroup from asset.copy_location_group_map where location = loc); + IF loc_group != 0 THEN + RETURN loc_group; + ELSE + RETURN loc; END IF; - RETURN loc; END; -$function$; -- !!! need some new indexes create index concurrently cp_location_idx on asset.copy (location);