比较Postgres中的软件版本 [英] Compare software version in postgres

查看:101
本文介绍了比较Postgres中的软件版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在postgres中比较软件版本(例如X.Y.Z> A.B.C)?我正在搜索字符串/varchar或版本"类型的函数.

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.

我发现 http://pgxn.org/dist/semver/doc/semver.html ,但我正在寻找替代方案(部署起来不太容易.)

I found out that http://pgxn.org/dist/semver/doc/semver.html, but i'm looking for alternatives (not so easy to deploy..)

非常感谢.

推荐答案

您可以将版本拆分为数组,然后执行

You can split the version to array and then do array comparison.

select regexp_split_to_array(v1, '\.')::int[] v1, 
       regexp_split_to_array(v2, '\.')::int[] v2,
       regexp_split_to_array(v1, '\.')::int[] > regexp_split_to_array(v2, '\.')::int[] cmp
from versions;

演示

这篇关于比较Postgres中的软件版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆