Reputation: 51
I'm creating a system for keeping track of which type of software, and which version of the software is licensed for each company. Some of the software has version numbers like 1.1.4 or similar with more than one decimal point.
I have tried saving it as a varchar for now, since I couldn't find a numerical data type that would take more than one decimal point. And, storing it as a varchar is fine, but I need to be able to search it for >= 1.1.2 or <= 2.5.1 and when I do that the system crashes. Searching for >= 1.2 will yield the result 2.5.1 for instance, but I would like to be able to search that last number too for accuracy.
Is there some datatype I'm missing (I'm quite new to this) or is there some other easy way of solving it?
Upvotes: 2
Views: 1924
Reputation: 26343
Assuming that the revision and patch values (in version.revision.patch
) will have a maximum of two digits, you could store them in an INT UNSIGNED
(or smaller) column as follows:
version * 10000 + revision * 100 + patch
With this approach, your search becomes >= 10102 or <= 20501
.
Upvotes: 4
Reputation: 26124
Not natively, no, as multiple decimal points aren't a common data type.
Your best bet would be saving it as varchar
like you have done, and then in your app code, splitting the number and doing the comparison by hand.
Upvotes: 1
Reputation: 476
I think your only options are
1) Use 3 separate integer fields for the version components but this makes the query a little more complex.
2) Save it as a string converted to the format xxxyyyzzz for example. i.e. 2.5.1 becomes a string "002005001". This makes the query easier.
Upvotes: 0