I am using PostgreSQL 9.4. My table has a jsonb
column:
CREATE TABLE "PreStage".transaction (
transaction_id serial NOT NULL,
transaction jsonb
CONSTRAINT pk_transaction PRIMARY KEY (transaction_id)
);
CREATE INDEX idxgin ON "PreStage".transaction USING gin (transaction);
I store transactions in terms of key / value in the JSONB column. One of the requirements is to search customer name from the key value, hence I am running a query like:
SELECT transaction as data FROM "PreStage".transaction
WHERE transaction->>('HCP_FST_NM') ilike ('%neer%');
What ever I do seems the query doesn't like the GIN index. How can I make the query use a GIN index with case insensitive pattern search?
I tried changing jsonb
column to text, indexing it using gin_trgm_ops
then search for required text, then converting the result to json
and then searching in the required key/value. This approach doesn't seem to work.
jsonb
column and add one or more example values. – Elvinaelvira