version-sort

Version sort (with alphas, betas, etc.) in ruby

荒凉一梦 提交于 2019-12-30 16:42:13
问题 How do I sort a list of versions in Ruby? I've seen stuff about natural sort, but this is a step beyond that. Input is a bunch of strings like this: input = ['10.0.0b12', '10.0.0b3', '10.0.0a2', '9.0.10', '9.0.3'] I can almost do it with the naturally gem: require 'naturally' Naturally.sort(input) => ["9.0.3", "9.0.10", "10.0.0a2", "10.0.0b12", "10.0.0b3"] Problem: 10.0.0b3 is sorted after 10.0.0b12; 10.0.0b3 should be first. Anyone have a way that works? Other languages are helpful too! 回答1:

Version sort (with alphas, betas, etc.) in ruby

旧街凉风 提交于 2019-12-30 16:40:06
问题 How do I sort a list of versions in Ruby? I've seen stuff about natural sort, but this is a step beyond that. Input is a bunch of strings like this: input = ['10.0.0b12', '10.0.0b3', '10.0.0a2', '9.0.10', '9.0.3'] I can almost do it with the naturally gem: require 'naturally' Naturally.sort(input) => ["9.0.3", "9.0.10", "10.0.0a2", "10.0.0b12", "10.0.0b3"] Problem: 10.0.0b3 is sorted after 10.0.0b12; 10.0.0b3 should be first. Anyone have a way that works? Other languages are helpful too! 回答1:

Sorting/ordering in MySQL

和自甴很熟 提交于 2019-12-20 03:13:19
问题 I'm having a little problem with trying to sort the contents of a table programs by the column prog_id which holds the id of each program in the following format: prog_id 1.0.1, 1.0.2, 1.0.3, ..., 1.0.10, 1.0.11, ..., 1.1.0, 1.1.1 etc When I sort by prog_id i get 1.0.1, 1.0.10, 1.0.11, 1.0.2, 1.0.3 ... which is correct as far as MySQL goes but not correct for the order in which the data should display. I tried using another column, orderby in which I could save an index and order by that but

Compare software version in postgres

ⅰ亾dé卋堺 提交于 2019-12-10 01:21:25
问题 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. 回答1: 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

Oracle SQL to Sort Version Numbers

时光总嘲笑我的痴心妄想 提交于 2019-11-30 15:57:11
In Oracle, just using the ORDER BY does not sort version numbers. My Version_Number field is declared as a VARCHAR and I cannot change it. For Example: The following versions : 1.20 1.9 1.18 1.13 1.5 1.11 2.0 1.8 1.3 1.2 1.1 1.0 1.10 should be sorted as 2.0 1.20 1.18 1.13 1.11 1.10 1.9 1.8 1.5 1.3 1.2 1.1 1.0 I have researched several posts but none of them seem to really serve my purpose or the answers were intended for SQL Server, etc and not Oracle. I came across this particular sql which seemed to look like it worked. select version_number from mytable order by lpad(version_number, 4) desc

Oracle SQL to Sort Version Numbers

旧时模样 提交于 2019-11-29 22:59:40
问题 In Oracle, just using the ORDER BY does not sort version numbers. My Version_Number field is declared as a VARCHAR and I cannot change it. For Example: The following versions : 1.20 1.9 1.18 1.13 1.5 1.11 2.0 1.8 1.3 1.2 1.1 1.0 1.10 should be sorted as 2.0 1.20 1.18 1.13 1.11 1.10 1.9 1.8 1.5 1.3 1.2 1.1 1.0 I have researched several posts but none of them seem to really serve my purpose or the answers were intended for SQL Server, etc and not Oracle. I came across this particular sql which