Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am using PostGIS to calculate length of interactions between two types of employees. I am performing the same set of operations for each area

I am using PostGIS to calculate length of interactions between two types of employees. I am performing the same set of operations for each area id. Here is my code:
CREATE OR REPLACE FUNCTION public.interactions_looped_ucmo_aic(areaid_array character varying[], d_date date, start_time__ timestamp without time zone, end_time__ timestamp without time zone)
RETURNS TABLE(area_id uuid, "createdAt_" timestamp without time zone, "updatedAt_" timestamp without time zone, "ID_" character varying, parent_imei character varying, child_imei character varying, parent_ping_time timestamp without time zone, child_ping_time timestamp without time zone, maxima timestamp without time zone, minima timestamp without time zone, "interactionID" character varying, interaction_type character varying)
LANGUAGE plpgsql
AS $function$
DECLARE
i integer :=1;
BEGIN
FOR i IN 1..array_length(areaid_array, 1) LOOP
RETURN QUERY
with pings as (
select
*
from
(--================= SELECTING Parent INFO
select
p.imei,
st_transform(p."geoJson", 32643) as geom,
"generatedAt" as t,
p."ID" as u_ping_id
from
campaign_pings p
where
"generatedAt" + interval '5 hours' between start_time__ and end_time__
and
p.imei in (
--multiple left joins
)
) u
left join (--================= SELECTING child INFO
SELECT
p.imei,
p."ID" as a_ping_id,
st_transform(p."geoJson", 32643) as geom,
"generatedAt" as t
FROM
campaign_pings p
where
"generatedAt"+ interval '5 hours' between start_time__ and end_time__
and
p.imei in (
--multiple left joins
)
) a on ST_DWithin(u."geom", a."geom", 30)
and a.t BETWEEN u.t - INTERVAL '30 seconds'
and u.t + INTERVAL '30 seconds'
where
a.imei is not null
)
--more code to calculate length of continuous interactions in minutes
;
END LOOP;
END
$function$
;
So essentially, I am performing the same set of operations for each area id. Is there a way to make use of caching here to reduce execution time? I mean to enforce the use of cache.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions

Question

What were your most important educational experiences?

Answered: 1 week ago

Question

Which personal relationships influenced you the most?

Answered: 1 week ago