AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题 / 168822
Accepted
Dr.YSG
Dr.YSG
Asked: 2017-04-01 13:45:32 +0800 CST2017-04-01 13:45:32 +0800 CST 2017-04-01 13:45:32 +0800 CST

PostgreSQL/PostGIS 9.6 破坏了我的复合索引

  • 772

在 PostgreSQL 9.2 中,我可以毫无问题地创建一个同时具有地理 (postGIS) 类型和整数作为复合索引的索引。但是现在(9.6)它抱怨索引的创建,我不明白它提供的提示:

列和数据都已正确创建,Postgres 抱怨创建索引。

ERROR: data type integer 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. 
********** Error**********  
ERROR: data type integer has no default operator class for access method "gist" 
SQL state: 42704 
Hint: You must specify an operator class for the index 
      or define a default operator class for the data type.

架构定义如下:

- Table: portal.inventory

-- DROP TABLE portal.inventory;

CREATE TABLE portal.inventory
(
  type character varying,
  pid integer,
  size bigint,
  date timestamp without time zone,
  path character varying,
  outline geography(Polygon,4326)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE portal.inventory
  OWNER TO postgres;

-- Index: portal.inventory_compound_idx

-- DROP INDEX portal.inventory_compound_idx;

CREATE INDEX inventory_compound_idx
  ON portal.inventory
  USING gist
  (outline, pid);

-- Index: portal.inventory_icompound_idx

-- DROP INDEX portal.inventory_icompound_idx;

CREATE INDEX inventory_icompound_idx
  ON portal.inventory
  USING gist
  (pid, outline);
postgresql postgis
  • 1 1 个回答
  • 1118 Views

1 个回答

  • Voted
  1. Best Answer
    joanolo
    2017-04-02T03:11:05+08:002017-04-02T03:11:05+08:00

    您需要在数据库中安装特定EXTENSION的:

    CREATE EXTENSION btree_gist ;
    

    根据btree_gist 上的 PostgreSQL 文档:

    btree_gist 提供了 GiST 索引运算符类,实现了数据类型 int2、int4、int8、float4、float8、numeric、timestamp with time zone、timestamp without time zone、time with time zone、time without time zone、date 的 B-tree 等效行为, interval, oid, money, char, varchar, text, bytea, bit, varbit, macaddr, inet, and cidr.

    通常,这些运算符类不会优于等效的标准 B 树索引方法,并且它们缺少标准 B 树代码的一项主要功能:强制执行唯一性的能力。但是,它们提供了 B 树索引所不具备的一些其他功能,如下所述。此外,这些运算符类在需要多列 GiST 索引时很有用,其中一些列的数据类型只能用 GiST 索引,而其他列只是简单的数据类型。最后,这些运算符类对于 GiST 测试很有用,并且可以作为开发其他 GiST 运算符类的基础。

    (强调我的)

    btree_gist是标准(当前)PostgreSQL 安装的一部分,因此,您实际上不需要在系统中安装任何文件。

    安装此扩展后,您可以在全新安装的 PostgreSQL 9.6.2上执行所有这些说明,而不会出现故障:

    -- If there is not there, create extension PostGis as well
    CREATE EXTENSION IF NOT EXISTS postgis ;
    
    -- Create Schema `portal`
    CREATE SCHEMA IF NOT EXISTS portal ;
    

    CREATE并毫无故障地执行所有语句。

    CREATE TABLE portal.inventory
    (
      type character varying,
      pid integer,
      size bigint,
      date timestamp without time zone,
      path character varying,
      outline geography(Polygon,4326)
    );
    
    CREATE INDEX inventory_compound_idx
      ON portal.inventory
      USING gist
      (outline, pid);
    
    CREATE INDEX inventory_icompound_idx
      ON portal.inventory
      USING gist
      (pid, outline);
    

    注意:根据@Erwin Brandstetter 的评论,这也是 9.2 版所需要的。所以,最有可能的是,如果您对9.2 版数据库进行转储CREATE EXTENSION btree_gist ;,则应该会出现该语句。

    • 10

相关问题

  • 我可以在使用数据库后激活 PITR 吗?

  • 运行时间偏移延迟复制的最佳实践

  • 存储过程可以防止 SQL 注入吗?

  • PostgreSQL 中 UniProt 的生物序列

  • PostgreSQL 9.0 Replication 和 Slony-I 有什么区别?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve