我要从 mysql 转到 postgres,但在创建索引时遇到问题。
使用 gist (point_col) 在表上创建索引 pointloc;
这是我得到的回复:
错误:数据类型 point 没有用于访问方法“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.
最佳答案
当我尝试时似乎工作正常:
test=# create table test (pt point);
CREATE TABLE
test=# create index pt_idx on test using gist (pt);
CREATE INDEX
您确定您的 point_col
实际上是 point
类型吗?因为,如果它是一个 varchar,那么如果没有 btree_gist contrib,它确实会悲惨地失败——即使那样它也不会很有用。
关于postgresql - postgres 创建索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6641504/