[ad_1]
Am using 9.4 postgres
Create table temp_JsonB (ID serial , name_it jsonb);
insert into temp_JsonB (name_it) values ('["a":"foo","b":"bar","c":"baz"]');
insert into temp_JsonB (name_it) values ('["c":"foo","d":"hee","c":"baz"]');
insert into temp_JsonB (name_it) values ('["g":"ggo","b":"bar","c":"raz"]');
CREATE INDEX temp_jsonb_gin
ON temp_JsonB
USING gin
(name_it jsonb_path_ops);
select ID, jsonb_agg(obj)
from temp_JsonB , jsonb_array_elements(name_it) obj
where obj ->>'b' ='bar'
group by 1;
I need to get only the particular element in the array, i used the above method to get it but unfortunately it is not making use of the index, Is there any way where i can re-write the code so it make use of index.
as in original production it has 2000+ rows and takes time, so index can be helpful here
[ad_2]
لینک منبع