CREATE TABLE test (a int4);
-- create index
-CREATE INDEX testidx ON test USING gin (a);
+CREATE INDEX testidx ON test USING GIN (a);
-- query
SELECT * FROM test WHERE a < 10;
CREATE TABLE test (a int4);
-- create index
-CREATE INDEX testidx ON test USING gist (a);
+CREATE INDEX testidx ON test USING GIST (a);
-- query
SELECT * FROM test WHERE a < 10;
-- nearest-neighbor search: find the ten entries closest to "42"
=> CREATE TABLE zoo (
cage INTEGER,
animal TEXT,
- EXCLUDE USING gist (cage WITH =, animal WITH <>)
+ EXCLUDE USING GIST (cage WITH =, animal WITH <>)
);
=> INSERT INTO zoo VALUES(123, 'zebra');
To use it, mention the class name in CREATE INDEX>,
for example
-CREATE INDEX ON my_table USING gist (my_inet_column inet_ops);
+CREATE INDEX ON my_table USING GIST (my_inet_column inet_ops);
= operator.
The following command is used to create a hash index:
-CREATE INDEX name ON table USING hash (column);
+CREATE INDEX name ON table USING HASH (column);
implement, see .)
An example of creating an index with this operator class is:
-CREATE INDEX idxgin ON api USING gin (jdoc);
+CREATE INDEX idxgin ON api USING GIN (jdoc);
The non-default GIN operator class jsonb_path_ops>
supports indexing the @>> operator only.
An example of creating an index with this operator class is:
-CREATE INDEX idxginp ON api USING gin (jdoc jsonb_path_ops);
+CREATE INDEX idxginp ON api USING GIN (jdoc jsonb_path_ops);
the "tags"> key is common, defining an index like this
may be worthwhile:
-CREATE INDEX idxgintags ON api USING gin ((jdoc -> 'tags'));
+CREATE INDEX idxgintags ON api USING GIN ((jdoc -> 'tags'));
Now, the WHERE> clause jdoc -> 'tags' ? 'qui'>
will be recognized as an application of the indexable
INSERT INTO test VALUES ('Top.Collections.Pictures.Astronomy.Stars');
INSERT INTO test VALUES ('Top.Collections.Pictures.Astronomy.Galaxies');
INSERT INTO test VALUES ('Top.Collections.Pictures.Astronomy.Astronauts');
-CREATE INDEX path_gist_idx ON test USING gist(path);
-CREATE INDEX path_idx ON test USING btree(path);
+CREATE INDEX path_gist_idx ON test USING GIST (path);
+CREATE INDEX path_idx ON test USING BTREE (path);
CREATE TABLE test_trgm (t text);
-CREATE INDEX trgm_idx ON test_trgm USING gist (t gist_trgm_ops);
+CREATE INDEX trgm_idx ON test_trgm USING GIST (t gist_trgm_ops);
or
-CREATE INDEX trgm_idx ON test_trgm USING gin (t gin_trgm_ops);
+CREATE INDEX trgm_idx ON test_trgm USING GIN (t gin_trgm_ops);
Next, create a trigram index on the word column:
-CREATE INDEX words_idx ON words USING gin(word gin_trgm_ops);
+CREATE INDEX words_idx ON words USING GIN (word gin_trgm_ops);
Now, a SELECT query similar to the previous example can
GiST and SP-GiST indexes can be created for table columns of range types.
For instance, to create a GiST index:
-CREATE INDEX reservation_idx ON reservation USING gist (during);
+CREATE INDEX reservation_idx ON reservation USING GIST (during);
A GiST or SP-GiST index can accelerate queries involving these range operators:
=>,
CREATE TABLE reservation (
during tsrange,
- EXCLUDE USING gist (during WITH &&)
+ EXCLUDE USING GIST (during WITH &&)
);
CREATE TABLE room_reservation (
room text,
during tsrange,
- EXCLUDE USING gist (room WITH =, during WITH &&)
+ EXCLUDE USING GIST (room WITH =, during WITH &&)
);
INSERT INTO room_reservation VALUES
To create a
GIN> index with fast updates disabled:
-CREATE INDEX gin_idx ON documents_table USING gin (locations) WITH (fastupdate = off);
+CREATE INDEX gin_idx ON documents_table USING GIN (locations) WITH (fastupdate = off);
linkend="textsearch-indexes">) to speed up text searches:
-CREATE INDEX pgweb_idx ON pgweb USING gin(to_tsvector('english', body));
+CREATE INDEX pgweb_idx ON pgweb USING GIN (to_tsvector('english', body));
Notice that the 2-argument version of to_tsvector is
configuration name is specified by another column, e.g.:
-CREATE INDEX pgweb_idx ON pgweb USING gin(to_tsvector(config_name, body));
+CREATE INDEX pgweb_idx ON pgweb USING GIN (to_tsvector(config_name, body));
where config_name> is a column in the pgweb>
Indexes can even concatenate columns:
-CREATE INDEX pgweb_idx ON pgweb USING gin(to_tsvector('english', title || ' ' || body));
+CREATE INDEX pgweb_idx ON pgweb USING GIN (to_tsvector('english', title || ' ' || body));
Then we create a
GIN index to speed up the search:
-CREATE INDEX textsearch_idx ON pgweb USING gin(textsearchable_index_col);
+CREATE INDEX textsearch_idx ON pgweb USING GIN (textsearchable_index_col);
Now we are ready to perform a fast full text search:
text search
- CREATE INDEX name ON table USING gist(column);
+ CREATE INDEX name ON table USING GIST (column);
text search
- CREATE INDEX name ON table USING gin(column);
+ CREATE INDEX name ON table USING GIN (column);