Well you actually can make the comparison like where "api_version > 'vX.X.XX" - well sort-of. The function regexp_split_to_array can be used to convert the version numbers to an integer array (need to lose the "v" ). Postgres can the compare integer arrays using the regular comparison operators.
-- fails to sort version properly and gets version incorrect
with versions (name, version) as
( values ('first', 'v0.0.1')
, ('second', 'v1.0.1')
, ('third', 'v1.2.1')
, ('forth','v1.10.1')
)
select name, substring(version,2) as version
, version > 'v1.3.5' "> v1.3.5"
from versions
order by 2;
-- properly sorts version and properly identifies the version order
with versions (name, version) as
( values ('first', 'v0.0.1')
, ('second', 'v1.0.1')
, ('third', 'v1.2.1')
, ('forth','v1.10.1')
)
select name, regexp_split_to_array(ver, '(\.)')::int[] as version
, regexp_split_to_array(ver, '(\.)')::int[] > regexp_split_to_array('1.3.5', '(\.)')::int[] "> v1.3.5"
from (select name, substring(version,2) as ver
from versions
) v
order by 2;
Now for actual version comparisons:
with versions (name, version) as
( values ('first', 'v0.0.1')
, ('second', 'v1.0.1')
, ('third', 'v1.2.1')
, ('forth','v1.10.1')
)
, target (version) as
( values ('v1.10.0') )
select name, version
from ( select name, regexp_split_to_array(ver, '(\.)')::int[] as version
from (select name, substring(version,2) as ver
from versions
) v
) v2
where version > (select regexp_split_to_array( (substring(version,2))::text , '(\.)')::int[] from target) ;
The complexity for above comes from having to deal with the "v" in your version number. Without that this reduces to:
with versions (name, version) as
( values ('first', '0.0.1')
, ('second', '1.0.1')
, ('third', '1.2.1')
, ('forth','1.10.1')
)
, target as
( select regexp_split_to_array( '1.10.0', '(\.)')::int[] as version)
select v.name, v.version
from (select name, regexp_split_to_array(version, '(\.)')::int[] as version from versions) v
where v.version > (select t.version from target t) ;