How to create an index for elements of an array in PostgreSQL?

后端 未结 3 1188
我在风中等你
我在风中等你 2020-12-03 19:51

With this schema:

create table object (
   obj_id      serial      primary key,
   name        varchar(80) not null unique,
   description text,
   tag_arr            


        
3条回答
  •  温柔的废话
    2020-12-03 20:36

    You can create GIN indexes on any 1-dimensional array with standard Postgres.
    Details in the manual here (last chapter).

    While operating with integer arrays (plain int4, not int2 or int8 and no NULL values) the additional supplied module intarray provides a lot more operators and typically superior performance. Install it (once per database) with:

    CREATE EXTENSION intarray;
    

    You can create GIN or GIST indexes on integer arrays. There are examples in the manual.
    CREATE EXTENSION requires PostgreSQL 9.1 or later. For older versions you need to run the supplied script.

提交回复
热议问题