hashlib
hashlib
pg_hashlib : Stable hash functions for Postgres
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 4400 | hashlib
|
pg_hashlib
|
1.1 |
UTIL
|
PostgreSQL
|
C
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d-r
|
No
|
Yes
|
No
|
Yes
|
yes
|
no
|
| Relationships | |
|---|---|
| See Also | xxhash
shacrypt
cryptint
pguecc
pgcrypto
gzip
bzip
zstd
|
build-deps: python3-docutils
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY
|
1.1 |
18
17
16
15
14
|
pg_hashlib |
- |
| RPM | PIGSTY
|
1.1 |
18
17
16
15
14
|
pg_hashlib_$v |
- |
| DEB | PIGSTY
|
1.1 |
18
17
16
15
14
|
postgresql-$v-pg-hashlib |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
el8.aarch64
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
el9.x86_64
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
el9.aarch64
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
el10.x86_64
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
el10.aarch64
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
d12.x86_64
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
d12.aarch64
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
d13.x86_64
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
d13.aarch64
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
u22.x86_64
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
u22.aarch64
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
u24.x86_64
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
u24.aarch64
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
PIGSTY 1.1
|
Source
pig build pkg pg_hashlib; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install pg_hashlib; # install via package name, for the active PG version
pig install hashlib; # install by extension name, for the current active PG version
pig install hashlib -v 18; # install for PG 18
pig install hashlib -v 17; # install for PG 17
pig install hashlib -v 16; # install for PG 16
pig install hashlib -v 15; # install for PG 15
pig install hashlib -v 14; # install for PG 14Create this extension with:
CREATE EXTENSION hashlib;Usage
Provides stable hash functions whose implementations do not change across PostgreSQL versions.
String Hashing (32-bit)
SELECT hash_string('hello', 'crc32');
SELECT hash_string('hello', 'murmur3');With optional initial value:
SELECT hash_string('hello', 'crc32', 42);String Hashing (64-bit)
SELECT hash64_string('hello', 'city64');
SELECT hash64_string('hello', 'siphash24');
SELECT hash64_string('hello', 'lookup3');String Hashing (128-bit)
SELECT hash128_string('hello', 'md5');
SELECT hash128_string('hello', 'city128');
SELECT hash128_string('hello', 'spooky');Integer Hashing
SELECT hash_int4(42); -- 32-bit hash of 32-bit integer
SELECT hash_int8(42::bigint); -- 64-bit hash of 64-bit integerAvailable Algorithms
| Algorithm | CPU-indep | Bits | Description |
|---|---|---|---|
crc32 |
yes | 32 | CRC32 |
murmur3 |
no | 32 | MurmurHash v3 |
md5 |
yes | 128 | MD5 |
city64 |
no | 64 | CityHash64 |
city128 |
no | 128 | CityHash128 |
siphash24 |
yes | 64 | SipHash-2-4 |
spooky |
no | 128 | SpookyHash |
lookup2 |
no | 64 | Jenkins lookup2 |
lookup3 |
no | 64 | Jenkins lookup3 CPU-native |
lookup3be |
yes | 64 | Jenkins lookup3 big-endian |
lookup3le |
yes | 64 | Jenkins lookup3 little-endian |
pgsql84 |
no | 64 | Hacked lookup3 in Postgres 8.4+ |
Integer algorithms: wang32, wang32mult, jenkins (32-bit); wang64, wang64to32 (64-bit). All are reversible (1:1 mapping), useful for creating random sort orders over unique IDs.
Last updated on