PostgreSQL Index | Postgres Index Types | Can we CREATE INDEX in Postgresql?
PostgreSQL has several index types: B-tree, Hash, GiST, SP-GiST, GIN and BRIN. Each Index type uses a different algorithm that is best suited to different types of queries. By default, the postgres CREATE INDEX command creates B-tree indexes, which fit the most common situations.
Postgres CREATE INDEX | Postgresql Index
When you create index PostgreSQL keep in mind that the postgresql index name should be the meaningful name and it should be identifiable to which table this index is created. So the PostgreSQL index naming should be easy to remember and meaningful. Specify any of the index type like B-tree, Hash, GiST, SP-GiST, GIN and BRIN, if not specified any index type by default it will create the post gre sql index with the type B-tree. The basic syntax of postgres CREATE INDEX statement is as follows.
CREATE INDEX index_name ON table_name;
Singlecolumn Index
CREATE INDEX IndexName ON TableName (ColumnName);
CREATE INDEX index_employee_name ON employee(name);
Can we CREATE INDEX on multiple columns in Postgresql?
Multicolumn Index | Create Index postgres multiple columns
CREATE INDEX IndexName ON TableName (ColumnName1,ColumnName2);
An example for the multicolumn index
CREATE INDEX index_employee_code_name ON employee (code,name);
Postgres add Unique Constraint - Unique Index
CREATE UNIQUE INDEX index_employee_code ON employee (code);
Postgres DROP INDEX
DROP INDEX index_employee_name;
Postgres show indexes
SELECT * FROM pg_indexes WHERE schemaname = 'public';
SELECT * FROM pg_indexes WHERE schemaname = 'public' AND tablename = 'item';
0 comments