I have firmware version strings into my table (like “4.2.2” or “4.2.16”)
How can I compare, select or sort them ?
I cannot use standard strings comparison : “4.2.2” is a seen by SQL greater than “4.2.16”
As version strings, I would like 4.2.16 to be greater than 4.2.2
I would like to consider that firmware version can have chars in them : 4.24a1, 4.25b3 … for this, usually, the subfield with chars has a fixed length.
how to proceed ?
Finally, I found another way to sort version strings.
I just justify the string before storing into de database in a way it is sortable.
As I am using the python Django framework, I just have created a VersionField that ‘encode’ the version string while storing and ‘decode’ it while reading, so that it is totally transparent for the application :
Here my code :