Postgresql – postgres index for “?|” JSONB operator

indexjsonpostgresql

I have a jsonb row with objects/dictionairies : {"a":1, "b":2, "c",3}

I want to query rows that contain a set of keys, ex:

SELECT * from my_table v 
WHERE v.my_jsonb_column::jsonb ?| array['b','a']

how can I create an index for this query ?

Best Answer

This index does it :

CREATE INDEX my_idx on my_table USING GIN (my_jsonb_column);