PostgreSQL version: 9.6.
The events
table has a visitors
JSONB column:
CREATE TABLE events (name VARCHAR(256), visitors JSONB);
The visitors
column contains a "flat" JSON array:
["John Doe","Frédéric Martin","Daniel Smith",...]
.
The events
table contains 10 million of rows, each row has between 1 and 20 visitors.
Is it possible to index the values of the array to perform efficient pattern-matching searches:
- left anchored: select events whose visitors match 'John%'
- right anchored: select events whose visitors match '%Doe'
- unaccented: select events whose visitors match 'Frederic%'
- case-insensitive: select events whose visitors match 'john%'
I am aware of the existence of the Postgres trigram extension gin_trgm_ops
enabling to create indexes for case-insensitive and right-anchored searches, but I can't figure out how to create trigram indexes for the content of "flat" JSON arrays.
I read Pattern matching on jsonb key/value and Index for finding an element in a JSON array but the solutions provided do not seem to apply to my use case.