- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有什么方法可以使用哈希方法创建主键吗?以下语句均无效:
oid char(30) primary key using hash
primary key(oid) using hash
最佳答案
我假设,您打算使用 hash index method / type .
主键是 constraints . 一些 约束可以创建索引以便正常工作(但不应依赖此事实)。 F.ex. UNIQUE
约束将创建一个唯一索引。请注意,目前只有 B-tree 支持唯一索引。 PRIMARY KEY
约束是 UNIQUE
和 NOT NULL
约束的组合,因此(目前)它仅支持 B 树。
如果需要,您也可以设置哈希索引(除了 PRIMARY KEY
约束之外)——但您不能使其唯一。
CREATE INDEX name ON table USING hash (column);
但是,如果您愿意这样做,您应该意识到哈希索引存在一些限制(直到 PostgreSQL 10):
Hash index operations are not presently WAL-logged, so hash indexes might need to be rebuilt with REINDEX after a database crash if there were unwritten changes. Also, changes to hash indexes are not replicated over streaming or file-based replication after the initial base backup, so they give wrong answers to queries that subsequently use them. For these reasons, hash index use is presently discouraged.
还有:
Currently, only the B-tree, GiST and GIN index methods support multicolumn indexes.
注意:不幸的是,oid
不是 PostgreSQL 中列的最佳名称,因为它也可以是 system column and type 的名称。 .
注释 2:char(n)
type is also discouraged .您可以使用 varchar
或 text
来代替,使用 CHECK
约束——或者(如果 id 非常像 uuid)uuid
type本身。
关于postgresql - 如何在postgresql中使用hash方法创建主键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24568157/
我是一名优秀的程序员,十分优秀!