Skip to content

pg_hashids

Short unique id generator for PostgreSQL, using hashids

pg_hashids · Short unique id generator for PostgreSQL, using hashids

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
4550pg_hashidspg_hashids1.3FUNCMITC
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-rNoYesNoYesyesno

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY1.319 18 17 16 15pg_hashids-
RPMPIGSTY1.319 18 17 16 15pg_hashids_$v-
DEBPIGSTY1.319 18 17 16 15postgresql-$v-pg-hashids-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3
el8.aarch64N/APIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3
el9.x86_64PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3
el9.aarch64PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3
el10.x86_64PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3
el10.aarch64PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3
d12.x86_64PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3
d12.aarch64PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3
d13.x86_64PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3
d13.aarch64PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3
u22.x86_64PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3
u22.aarch64PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3
u24.x86_64PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3
u24.aarch64PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3
u26.x86_64PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3
u26.aarch64PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3PIGSTY 1.3
PackageVersionOSORGSIZEFile URL
pg_hashids_191.3el9.x86_64pigsty33.8 KiBpg_hashids_19-1.3-1PGSTY.el9.x86_64.rpm
pg_hashids_191.3el9.aarch64pigsty32.9 KiBpg_hashids_19-1.3-1PGSTY.el9.aarch64.rpm
pg_hashids_191.3el10.x86_64pigsty33.8 KiBpg_hashids_19-1.3-1PGSTY.el10.x86_64.rpm
pg_hashids_191.3el10.aarch64pigsty33.5 KiBpg_hashids_19-1.3-1PGSTY.el10.aarch64.rpm
postgresql-19-pg-hashids1.3d12.x86_64pigsty27.3 KiBpostgresql-19-pg-hashids_1.3-1PGSTY~bookworm_amd64.deb
postgresql-19-pg-hashids1.3d12.aarch64pigsty26.5 KiBpostgresql-19-pg-hashids_1.3-1PGSTY~bookworm_arm64.deb
postgresql-19-pg-hashids1.3d13.x86_64pigsty27.3 KiBpostgresql-19-pg-hashids_1.3-1PGSTY~trixie_amd64.deb
postgresql-19-pg-hashids1.3d13.aarch64pigsty26.6 KiBpostgresql-19-pg-hashids_1.3-1PGSTY~trixie_arm64.deb
postgresql-19-pg-hashids1.3u22.x86_64pigsty27.6 KiBpostgresql-19-pg-hashids_1.3-1PGSTY~jammy_amd64.deb
postgresql-19-pg-hashids1.3u22.aarch64pigsty26.7 KiBpostgresql-19-pg-hashids_1.3-1PGSTY~jammy_arm64.deb
postgresql-19-pg-hashids1.3u24.x86_64pigsty27.7 KiBpostgresql-19-pg-hashids_1.3-1PGSTY~noble_amd64.deb
postgresql-19-pg-hashids1.3u24.aarch64pigsty26.8 KiBpostgresql-19-pg-hashids_1.3-1PGSTY~noble_arm64.deb
postgresql-19-pg-hashids1.3u26.x86_64pigsty27.2 KiBpostgresql-19-pg-hashids_1.3-1PGSTY~resolute_amd64.deb
postgresql-19-pg-hashids1.3u26.aarch64pigsty26.8 KiBpostgresql-19-pg-hashids_1.3-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_hashids_181.3el8.x86_64pigsty34.3 KiBpg_hashids_18-1.3-1PGSTY.el8.x86_64.rpm
pg_hashids_181.3el8.aarch64pigsty33.4 KiBpg_hashids_18-1.3-1PGSTY.el8.aarch64.rpm
pg_hashids_181.3el9.x86_64pigsty33.8 KiBpg_hashids_18-1.3-1PGSTY.el9.x86_64.rpm
pg_hashids_181.3el9.aarch64pigsty32.9 KiBpg_hashids_18-1.3-1PGSTY.el9.aarch64.rpm
pg_hashids_181.3el10.x86_64pigsty33.8 KiBpg_hashids_18-1.3-1PGSTY.el10.x86_64.rpm
pg_hashids_181.3el10.aarch64pigsty33.5 KiBpg_hashids_18-1.3-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-hashids1.3d12.x86_64pigsty27.3 KiBpostgresql-18-pg-hashids_1.3-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-hashids1.3d12.aarch64pigsty26.5 KiBpostgresql-18-pg-hashids_1.3-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-hashids1.3d13.x86_64pigsty27.4 KiBpostgresql-18-pg-hashids_1.3-1PGSTY~trixie_amd64.deb
postgresql-18-pg-hashids1.3d13.aarch64pigsty26.5 KiBpostgresql-18-pg-hashids_1.3-1PGSTY~trixie_arm64.deb
postgresql-18-pg-hashids1.3u22.x86_64pigsty27.6 KiBpostgresql-18-pg-hashids_1.3-1PGSTY~jammy_amd64.deb
postgresql-18-pg-hashids1.3u22.aarch64pigsty26.7 KiBpostgresql-18-pg-hashids_1.3-1PGSTY~jammy_arm64.deb
postgresql-18-pg-hashids1.3u24.x86_64pigsty27.7 KiBpostgresql-18-pg-hashids_1.3-1PGSTY~noble_amd64.deb
postgresql-18-pg-hashids1.3u24.aarch64pigsty26.8 KiBpostgresql-18-pg-hashids_1.3-1PGSTY~noble_arm64.deb
postgresql-18-pg-hashids1.3u26.x86_64pigsty27.2 KiBpostgresql-18-pg-hashids_1.3-1PGSTY~resolute_amd64.deb
postgresql-18-pg-hashids1.3u26.aarch64pigsty26.8 KiBpostgresql-18-pg-hashids_1.3-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_hashids_171.3el8.x86_64pigsty34.3 KiBpg_hashids_17-1.3-1PGSTY.el8.x86_64.rpm
pg_hashids_171.3el8.aarch64pigsty33.4 KiBpg_hashids_17-1.3-1PGSTY.el8.aarch64.rpm
pg_hashids_171.3el9.x86_64pigsty33.8 KiBpg_hashids_17-1.3-1PGSTY.el9.x86_64.rpm
pg_hashids_171.3el9.aarch64pigsty32.9 KiBpg_hashids_17-1.3-1PGSTY.el9.aarch64.rpm
pg_hashids_171.3el10.x86_64pigsty33.8 KiBpg_hashids_17-1.3-1PGSTY.el10.x86_64.rpm
pg_hashids_171.3el10.aarch64pigsty33.5 KiBpg_hashids_17-1.3-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-hashids1.3d12.x86_64pigsty27.2 KiBpostgresql-17-pg-hashids_1.3-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-hashids1.3d12.aarch64pigsty26.5 KiBpostgresql-17-pg-hashids_1.3-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-hashids1.3d13.x86_64pigsty27.3 KiBpostgresql-17-pg-hashids_1.3-1PGSTY~trixie_amd64.deb
postgresql-17-pg-hashids1.3d13.aarch64pigsty26.6 KiBpostgresql-17-pg-hashids_1.3-1PGSTY~trixie_arm64.deb
postgresql-17-pg-hashids1.3u22.x86_64pigsty28.5 KiBpostgresql-17-pg-hashids_1.3-1PGSTY~jammy_amd64.deb
postgresql-17-pg-hashids1.3u22.aarch64pigsty27.7 KiBpostgresql-17-pg-hashids_1.3-1PGSTY~jammy_arm64.deb
postgresql-17-pg-hashids1.3u24.x86_64pigsty27.7 KiBpostgresql-17-pg-hashids_1.3-1PGSTY~noble_amd64.deb
postgresql-17-pg-hashids1.3u24.aarch64pigsty26.8 KiBpostgresql-17-pg-hashids_1.3-1PGSTY~noble_arm64.deb
postgresql-17-pg-hashids1.3u26.x86_64pigsty27.1 KiBpostgresql-17-pg-hashids_1.3-1PGSTY~resolute_amd64.deb
postgresql-17-pg-hashids1.3u26.aarch64pigsty26.8 KiBpostgresql-17-pg-hashids_1.3-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_hashids_161.3el8.x86_64pigsty34.3 KiBpg_hashids_16-1.3-1PGSTY.el8.x86_64.rpm
pg_hashids_161.3el8.aarch64pigsty33.4 KiBpg_hashids_16-1.3-1PGSTY.el8.aarch64.rpm
pg_hashids_161.3el9.x86_64pigsty33.8 KiBpg_hashids_16-1.3-1PGSTY.el9.x86_64.rpm
pg_hashids_161.3el9.aarch64pigsty32.9 KiBpg_hashids_16-1.3-1PGSTY.el9.aarch64.rpm
pg_hashids_161.3el10.x86_64pigsty33.8 KiBpg_hashids_16-1.3-1PGSTY.el10.x86_64.rpm
pg_hashids_161.3el10.aarch64pigsty33.5 KiBpg_hashids_16-1.3-1PGSTY.el10.aarch64.rpm
postgresql-16-pg-hashids1.3d12.x86_64pigsty27.3 KiBpostgresql-16-pg-hashids_1.3-1PGSTY~bookworm_amd64.deb
postgresql-16-pg-hashids1.3d12.aarch64pigsty26.5 KiBpostgresql-16-pg-hashids_1.3-1PGSTY~bookworm_arm64.deb
postgresql-16-pg-hashids1.3d13.x86_64pigsty27.3 KiBpostgresql-16-pg-hashids_1.3-1PGSTY~trixie_amd64.deb
postgresql-16-pg-hashids1.3d13.aarch64pigsty26.6 KiBpostgresql-16-pg-hashids_1.3-1PGSTY~trixie_arm64.deb
postgresql-16-pg-hashids1.3u22.x86_64pigsty28.5 KiBpostgresql-16-pg-hashids_1.3-1PGSTY~jammy_amd64.deb
postgresql-16-pg-hashids1.3u22.aarch64pigsty27.7 KiBpostgresql-16-pg-hashids_1.3-1PGSTY~jammy_arm64.deb
postgresql-16-pg-hashids1.3u24.x86_64pigsty27.7 KiBpostgresql-16-pg-hashids_1.3-1PGSTY~noble_amd64.deb
postgresql-16-pg-hashids1.3u24.aarch64pigsty26.8 KiBpostgresql-16-pg-hashids_1.3-1PGSTY~noble_arm64.deb
postgresql-16-pg-hashids1.3u26.x86_64pigsty27.1 KiBpostgresql-16-pg-hashids_1.3-1PGSTY~resolute_amd64.deb
postgresql-16-pg-hashids1.3u26.aarch64pigsty26.8 KiBpostgresql-16-pg-hashids_1.3-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_hashids_151.3el8.x86_64pigsty34.5 KiBpg_hashids_15-1.3-1PGSTY.el8.x86_64.rpm
pg_hashids_151.3el8.aarch64pigsty33.6 KiBpg_hashids_15-1.3-1PGSTY.el8.aarch64.rpm
pg_hashids_151.3el9.x86_64pigsty35.1 KiBpg_hashids_15-1.3-1PGSTY.el9.x86_64.rpm
pg_hashids_151.3el9.aarch64pigsty34.2 KiBpg_hashids_15-1.3-1PGSTY.el9.aarch64.rpm
pg_hashids_151.3el10.x86_64pigsty35.2 KiBpg_hashids_15-1.3-1PGSTY.el10.x86_64.rpm
pg_hashids_151.3el10.aarch64pigsty35.0 KiBpg_hashids_15-1.3-1PGSTY.el10.aarch64.rpm
postgresql-15-pg-hashids1.3d12.x86_64pigsty27.5 KiBpostgresql-15-pg-hashids_1.3-1PGSTY~bookworm_amd64.deb
postgresql-15-pg-hashids1.3d12.aarch64pigsty26.8 KiBpostgresql-15-pg-hashids_1.3-1PGSTY~bookworm_arm64.deb
postgresql-15-pg-hashids1.3d13.x86_64pigsty27.6 KiBpostgresql-15-pg-hashids_1.3-1PGSTY~trixie_amd64.deb
postgresql-15-pg-hashids1.3d13.aarch64pigsty26.9 KiBpostgresql-15-pg-hashids_1.3-1PGSTY~trixie_arm64.deb
postgresql-15-pg-hashids1.3u22.x86_64pigsty29.8 KiBpostgresql-15-pg-hashids_1.3-1PGSTY~jammy_amd64.deb
postgresql-15-pg-hashids1.3u22.aarch64pigsty29.0 KiBpostgresql-15-pg-hashids_1.3-1PGSTY~jammy_arm64.deb
postgresql-15-pg-hashids1.3u24.x86_64pigsty28.9 KiBpostgresql-15-pg-hashids_1.3-1PGSTY~noble_amd64.deb
postgresql-15-pg-hashids1.3u24.aarch64pigsty28.1 KiBpostgresql-15-pg-hashids_1.3-1PGSTY~noble_arm64.deb
postgresql-15-pg-hashids1.3u26.x86_64pigsty28.5 KiBpostgresql-15-pg-hashids_1.3-1PGSTY~resolute_amd64.deb
postgresql-15-pg-hashids1.3u26.aarch64pigsty28.2 KiBpostgresql-15-pg-hashids_1.3-1PGSTY~resolute_arm64.deb

Source

pig build pkg pg_hashids;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pg_hashids;		# install by package name

pig install pg_hashids -v 19;   # install for PG 19
pig install pg_hashids -v 18;   # install for PG 18
pig install pg_hashids -v 17;   # install for PG 17
pig install pg_hashids -v 16;   # install for PG 16
pig install pg_hashids -v 15;   # install for PG 15

Create this extension with:

CREATE EXTENSION pg_hashids;

Usage

pg_hashids: generate short unique ids from integers

Converts numbers like 347 into strings like “yr8”. Useful for obfuscating database primary keys.

CREATE EXTENSION pg_hashids;

Functions

FunctionDescription
id_encode(number [, salt [, min_length [, alphabet]]])Encode an integer to a hashid string
id_decode(hash, salt, min_length [, alphabet])Decode a hashid string back to integer array
id_decode_once(hash [, salt [, min_length [, alphabet]]])Decode a hashid string back to a single integer

Examples

-- Basic encoding
SELECT id_encode(1001);                                    -- 'jNl'
SELECT id_encode(1234567, 'This is my salt');              -- 'Pdzxp'
SELECT id_encode(1234567, 'This is my salt', 10);          -- 'PlRPdzxpR7'

-- Custom alphabet
SELECT id_encode(1234567, 'This is my salt', 10, 'abcdefghijABCDxFGHIJ1234567890');
-- '3GJ956J9B9'

-- Decoding (use the same salt!)
SELECT id_decode('PlRPdzxpR7', 'This is my salt', 10);     -- 1234567
SELECT id_decode_once('jNl');                               -- 1001
SELECT id_decode_once('Pdzxp', 'This is my salt');          -- 1234567

Table reader