postgres创建一个索引

Blu*_*ers 6 postgresql

我将从mysql转到postgres,我在创建索引时遇到问题.

CREATE INDEX pointsloc ON table USING gist(point_col);

这是我回复的回复:

错误:数据类型点没有访问方法"gist"的默认运算符类提示:必须为索引指定运算符类或为数据类型定义默认运算符类.

我已经看到我需要为索引指定运算符类,可以使用不同的类,具体取决于您希望在列上使用的运算符的类型.我希望使用@>或〜来查找点是否在多边形内.

我如何指定运算符类?帮助请一定是一件简单的事情,但我很难过!

编辑

下面是我尝试向分支表添加索引的打印屏幕:

                                   Table "public.branch"
      Column      |       Type       |                      Modifiers                      
------------------+------------------+-----------------------------------------------------
 id               | integer          | not null default nextval('branch_id_seq'::regclass)
 name             | character(120)   | 
 center_point_lat | double precision | 
 center_point_lng | double precision | 
 center_point     | point            | 
Indexes:
    "branch_pkey" PRIMARY KEY, btree (id)

paul=# create index pt_idx on branch using gist (center_point);
ERROR:  data type point has no default operator class for access method "gist"
HINT:  You must specify an operator class for the index or define a default operator class for the data type.
Run Code Online (Sandbox Code Playgroud)

Den*_*rdy 3

当我尝试时似乎工作正常:

test=# create table test (pt point);
CREATE TABLE
test=# create index pt_idx on test using gist (pt);
CREATE INDEX
Run Code Online (Sandbox Code Playgroud)

你确定你的point_col确实类型point吗?因为,如果它是一个 varchar,那么如果没有 btree_gist contrib,它确实会严重失败 - 即使这样它也不会很有用。

  • PG 8.1已经超过6年了。这不仅仅是过时的。真是无可救药啊。:-| (2认同)