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);