select
picks ->> 'pid' as playerid, e.id,
e.sportid, e.leagueid,
e.islive, e.status,
e.locationid, e.participants, em.bets
From
sfbr.eventmarket em
join sfbr.events e on em.eventid = e.id,
jsonb_array_elements(em.bets) b,
jsonb_array_elements((b->> 'b')::jsonb) picks
where (picks ->> 'pid') is not null
and (picks ->> 'ec') is null
and e.startdatetime > '2019-09-04 07:29:00.690834' and (picks ->> 'pid') in
('1880686','1796512','1838464','851658','66675')
order by e.startdatetime desc;
Hi, This query takes forever (2-3minutes), how can i write it so i dont have to do jsonb_array_elements twice!? is there any way to index 'pid' field in array inside of an array?
Thanks in advance