Is there a way to compare software version (e.g. X.Y.Z > A.B.C) in postgres ? I'm searching for a function on string/varchar or a "version" type.
I found out that http://pgxn.org/dist/semver/doc/semver.html, but i'm looking for alternatives (not so easy to deploy..)
Thanks a lot.
Maybe you can add a pl function, in my case I have used python and distutils.version:
You need the postgresql-plpython package.
An alternative approach is to use
This returns a version number that's simpler to compare. e.g. 90610 for 9.6.10.
As already suggested an easy way is to work with a numeric format of the version. The variable 'server_version_num' contains a numeric format of the version.
Eg.
version 10.5 => 100500
select current_setting('server_version_num')
return a number that can be easily compared with another version number.
You can split the version to array and then do array comparison.
demo
Use the cheaper
string_to_array()
. There is no need for expensive regular expressions here:SQL Fiddle.