GiN(Generalized Inverted Index) is inverted index, a structure that has only a single index entry per a key and stores the mapping information(posting list) of all key rows to have the same value in the index entry. In postgreSQL, the key is stored in the index entry and mapping information for the key is stored in the posting tree. To search the index entry and posting tree a B-Tree is used. Therefore, GIN is useful when an index must map many values on a row, such as indexing array, documents.
I suppose to that before creating a GIN index, you are making some mistake. as you see here PostgreSQL GIN pg_trgm default operator class
To Creates a GIN (Generalized Inverted Index) the syntax should be like
CREATE INDEX name ON table USING gin(column);
Creates a GIN (Generalized Inverted Index)-based index. The column must be of tsvector type.
Default operator class jsonb_ops supports existence operators( ?, ?&, ?| ) and containment operator( @> ). And jsonb_path_ops supports the containment operator only. Therefore GIN index is only possible to search for a particular key or key-values.
When we use ->> operator of JSONB, PostgreSQL can use B-tree or Hash index for processing the operations. ->> operator returns the value of the specified attribute in text format. PostgreSQL can use indexes for the text results as compare operands. GIN index can be used by GIN jsonb operator class.
To see the json operator Here
For further ref Here and Here.
jsonb
can be indexed withgin
. And you are clearly trying to create an index on the column that is type ofjson
. If you can't change column type you can have for examlebtree
index on some key in thejson
. Like so:CREATE INDEX ON api((column->>'id'));