postgresql-libversion
April 8, 2024 ยท View on GitHub
PostgreSQL extension with support for version string comparison through libversion.
API
The extension implements:
version_compare2(text, text)function which takes two strings, compares them as versions and returns integer -1 if second version is greater, 1 if first version is greater and 0 if versions are equal.version_compare4(text, text, int, int), which does the same, additionally allowing to specify flags for either side of comparison to tune it. See libversion documentation for complete description of flags. Here, flag values are provided as functions:VERSIONFLAG_P_IS_PATCH(),VERSIONFLAG_ANY_IS_PATCH()VERSIONFLAG_LOWER_BOUND()VERSIONFLAG_UPPER_BOUND()
versiontexttype which behaves just liketext, but compares as version strings.
Synopsis
CREATE EXTENSION libversion;
# CREATE EXTENSION
SELECT version_compare2('1.10', '1.2');
# 1
SELECT version_compare2('1.0', '1.0.0');
# 0
SELECT version_compare4('1.0p1', '1.0', VERSIONFLAG_P_IS_PATCH(), 0);
# 1
SELECT '1.10'::versiontext > '1.2'::versiontext;
# t
SELECT '1.0'::versiontext = '1.0.0'::versiontext;
# t
Installation
The extension uses standard PostgreSQL Makefile infrastructure.
Run
make && make install
to build and install. The build requires libversion and pkgconfig installed.
Author
- Dmitry Marakasov amdmi3@amdmi3.ru
- Contains code from PostgreSQL 9.6 citext extension