Skip to content

semver

Semantic version data type

Overview

PackageVersionCategoryLicenseLanguage
pg_semver0.42.0TYPEPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
3510semverNoYesNoYesNoYes-

0.42.0 changes hashing; REINDEX all semver hash indexes.

Version

TypeRepoVersionPG VerPackageDeps
EXTPGDG0.42.01817161514pg_semver-
RPMPGDG0.42.01817161514semver_$v-
DEBPGDG0.42.01817161514postgresql-$v-semver-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
u22.x86_64
u22.aarch64
u24.x86_64
u24.aarch64
u26.x86_64
u26.aarch64

Build

You can build the RPM / DEB packages for pg_semver using pig build:

pig build pkg pg_semver         # build RPM / DEB packages

Install

You can install pg_semver directly. First, make sure the PGDG repository is added and enabled:

pig repo add pgdg -u          # Add PGDG repo and update cache

Install the extension using pig or apt/yum/dnf:

Install
pig install pg_semver;          # Install for current active PG version
pig
pig ext install -y pg_semver -v 18  # PG 18
pig ext install -y pg_semver -v 17  # PG 17
pig ext install -y pg_semver -v 16  # PG 16
pig ext install -y pg_semver -v 15  # PG 15
pig ext install -y pg_semver -v 14  # PG 14
dnf
dnf install -y semver_18       # PG 18
dnf install -y semver_17       # PG 17
dnf install -y semver_16       # PG 16
dnf install -y semver_15       # PG 15
dnf install -y semver_14       # PG 14
apt
apt install -y postgresql-18-semver   # PG 18
apt install -y postgresql-17-semver   # PG 17
apt install -y postgresql-16-semver   # PG 16
apt install -y postgresql-15-semver   # PG 15
apt install -y postgresql-14-semver   # PG 14

Create Extension:

CREATE EXTENSION semver;

Usage

Sources:

semver provides a Semantic Versioning 2.0.0 data type, comparison operators and the semverrange range type. Version 0.42.0 changes hashing: after upgrading, rebuild every hash index on semver values.

Core Workflow

CREATE EXTENSION semver;
SELECT '1.2.0'::semver > '1.2.0-b1'::semver;
SELECT '1.2.0'::semver = '1.2.0+build1'::semver;
SELECT to_semver('1.0'), is_semver('1.2.0');
SELECT get_semver_major('4.2.0'::semver);
SELECT '1.0.5'::semver <@ '[1.0.0,2.0.0)'::semverrange;

Operational Boundaries

semver(text) and casts from text require valid semantic versions; to_semver(text) performs more permissive conversion, and is_semver(text) checks validity. get_semver_major, get_semver_minor and get_semver_patch return integer components; get_semver_prerelease returns the prerelease text. Casts also accept numeric, real, double precision, integer, bigint and smallint. Version 0.42.0 rejects Infinity and NaN instead of producing malformed versions.

The comparison operators =, <>, <, <=, > and >=, plus MIN(semver) and MAX(semver), use semantic ordering. A prerelease sorts before its final release; build metadata does not affect precedence. Btree and hash indexes are available. semverrange supports standard range operations.

Install this native, untrusted extension with administrator privileges. After installing 0.42.0, run ALTER EXTENSION semver UPDATE and use REINDEX on every existing hash index containing semver keys. The hash change is not repaired by updating the extension’s SQL definitions alone. The release also fixes ordering of alphanumeric prerelease identifiers beginning with a digit and validation of strings with multiple plus signs. When upgrading from old releases, inspect the upstream compatibility notes for previously accepted invalid values.

Was this page helpful?