postgresql - postgres 创建索引

标签 postgresql

我要从 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/

相关文章:

mysql - 同一个表中相关项的 SQL 查询

sql - 使用产生两列的子查询删除(在 Postgresql 中)

ruby-on-rails - 使用 Postgres 全文搜索来搜索完全匹配的最佳方法是什么?

sql - TypeORM:列必须出现在 GROUP BY 子句中或在聚合函数中使用

python - SQL 查询中无法识别的变量(从 CLI 参数分配)

sql - 如何修复 postgresql UPSERT 中的语法错误?

python - Pandas 使用 read_sql_table 占用过多内存

sql - 语言依赖于行时的高效全文搜索

postgresql - 如何使用多个条件过滤 jsonb?

sql - JOIN (SELECT ...) ue ON 1=1?