简体   繁体   中英

Using numbers with multiple decimal points (ex. 1.4.4) in MySql, is it possible?

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?

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 .

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.

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. ie 2.5.1 becomes a string "002005001". This makes the query easier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM