select dest to_lib,count(dest) to_count from transits group by 1 order by 1
),
orgs as (
- select id from actor.org_unit where id between 10 and 17
+ select id from actor.org_unit group by 1
)
select orgs.id as lib,coalesce(from_count,0),coalesce(to_count,0),coalesce(to_count,0)-coalesce(from_count,0) as transit_vector from orgs left join tto on orgs.id=to_lib left join tfrom on orgs.id=from_lib;
END;
-- !!! smart_float.loc_or_locgroup !!!
CREATE OR REPLACE FUNCTION smart_float.loc_or_locgroup(loc integer)
- RETURNS integer
+ RETURNS integer
LANGUAGE plpgsql
-AS $function$
-DECLARE
+ STABLE COST 10 AS $function$ DECLARE
found_loc BOOLEAN;
loc_group INT;
BEGIN
- SELECT INTO found_loc loc IN (select distinct(shelf_location) from config.smart_float where shelf_is_group is FALSE);
+ 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 distinct(shelf_location) from config.smart_float where shelf_is_group is TRUE);
+ 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;
END;
$function$;
-
-- !!! need some new indexes
create index concurrently cp_location_idx on asset.copy (location);