In this article, I will talk about how we can set conditions when creating an index in PostgreSQL.
As everyone knows, when creating an index, we can create an index by giving a table name and a column name, but it takes up disk space according to the data in these columns, so what do I do when I want to create an index by specifying only a certain part of those columns or only the where condition in the query I use a lot?
In this case, one of the possibilities Postgresql offers us (after specifying the columns while creating the index) is that we can write a where condition.
In the example below, I want to index two columns in our table named indextabled1 and index the data that is less than 21 in column1 and the data that only contains “F” in column2.
1 | CREATE INDEX IX_4 ON indextabled1(column1,column2) WHERE column1<21 and column2='F'; |