hashtypes
包括SHA1,MD5在内的多种哈希数据类型
仓库
adjust/hashtypes
https://github.com/adjust/hashtypes/
源码
hashtypes-0.1.5.tar.gz
hashtypes-0.1.5.tar.gz
概览
| 扩展包名 | 版本 | 分类 | 许可证 | 语言 |
|---|---|---|---|---|
hashtypes | 0.1.5 | TYPE | PostgreSQL | C |
| ID | 扩展名 | Bin | Lib | Load | Create | Trust | Reloc | 模式 |
|---|---|---|---|---|---|---|---|---|
| 3750 | hashtypes | 否 | 是 | 否 | 是 | 否 | 否 | - |
| 相关扩展 | prefix semver unit pgpdf pglite_fusion md5hash asn1oid roaringbitmap |
|---|
版本
| 类型 | 仓库 | 版本 | PG 大版本 | 包名 | 依赖 |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.1.5 | 1817161514 | hashtypes | - |
| RPM | PIGSTY | 0.1.5 | 1817161514 | hashtypes_$v | - |
| DEB | PIGSTY | 0.1.5 | 1817161514 | postgresql-$v-hashtypes | - |
构建
您可以使用 pig build 命令构建 hashtypes 扩展的 RPM / DEB 包:
pig build pkg hashtypes # 构建 RPM / DEB 包
安装
您可以直接安装 hashtypes 扩展包的预置二进制包,首先确保 PGDG 和 PIGSTY 仓库已经添加并启用:
pig repo add pgsql -u # 添加仓库并更新缓存
使用 pig 或者是 apt/yum/dnf 安装扩展:
pig install hashtypes; # 当前活跃 PG 版本安装
pig ext install -y hashtypes -v 18 # PG 18
pig ext install -y hashtypes -v 17 # PG 17
pig ext install -y hashtypes -v 16 # PG 16
pig ext install -y hashtypes -v 15 # PG 15
pig ext install -y hashtypes -v 14 # PG 14
dnf install -y hashtypes_18 # PG 18
dnf install -y hashtypes_17 # PG 17
dnf install -y hashtypes_16 # PG 16
dnf install -y hashtypes_15 # PG 15
dnf install -y hashtypes_14 # PG 14
apt install -y postgresql-18-hashtypes # PG 18
apt install -y postgresql-17-hashtypes # PG 17
apt install -y postgresql-16-hashtypes # PG 16
apt install -y postgresql-15-hashtypes # PG 15
apt install -y postgresql-14-hashtypes # PG 14
创建扩展:
CREATE EXTENSION hashtypes;
用法
hashtypes 扩展提供了原生数据类型,用于以二进制形式存储哈希值和校验和,相比文本存储更节省空间。
CREATE EXTENSION hashtypes;
数据类型
| 类型 | 存储大小 | 描述 |
|---|---|---|
sha1 | 20 字节 | SHA-1 哈希(160 位) |
sha224 | 28 字节 | SHA-224 哈希(224 位) |
sha256 | 32 字节 | SHA-256 哈希(256 位) |
sha384 | 48 字节 | SHA-384 哈希(384 位) |
sha512 | 64 字节 | SHA-512 哈希(512 位) |
crc32 | 4 字节 | CRC-32 校验和 |
用法
CREATE TABLE objects (
hash sha256 PRIMARY KEY,
data bytea
);
INSERT INTO objects VALUES (
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
'\x'
);
SELECT * FROM objects WHERE hash = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855';
运算符
所有类型均支持比较运算符:=、<>、<、>、<=、>=。
索引支持
所有类型均提供 Btree 和 Hash 索引运算符类。
类型转换
所有类型均支持与 text 和 bytea 之间的双向转换。