Is there a way to index in postgres for fast substring searches

前端 未结 3 1069
闹比i
闹比i 2021-02-04 05:43

I have a database and want to be able to look up in a table a search that\'s something like: select * from table where column like \"abc%def%ghi\" or select * from table where c

3条回答
  •  情深已故
    2021-02-04 06:32

    If you need just to, for instance, get unique substrings in an entire table, you can create a substring index:

    CREATE INDEX  i_test_sbstr ON tablename (substring(columname, 5, 3)); 
    -- start at position 5, go for 3 characters
    
    It is important that the substring() parameters in the index definition are
    the same as you use in your query.
    

    ref: http://www.postgresql.org/message-id/BANLkTinjUhGMc985QhDHKunHadM0MsGhjg@mail.gmail.com

提交回复
热议问题