This is a cross-posting from an original question at How to check version is greater than some base value?
When calling MySQL
SELECT @@VERSION; or
SELECT VERSION();, I get for instance '5.7.11-log'. Is there a "well-known" way to check if the version is greater (or smaller) than some major.minor.patch version? If not a well-known way, is there a way without using a temporary table or a user-defined function (there probably is, but for a reason or another currently eludes me)? I would use this to check if there's support for JSON type type that was introduced in version 5.7.8.
Upon researching this more, it appears this is a bit tougher nut for my skills to crack. For instance, I could write something like
SELECT SUBSTRING_INDEX(@@VERSION, '.', 1) AS major, SUBSTRING_INDEX(SUBSTRING_INDEX(@@VERSION,'.', 2), '.', -1) AS minor, SUBSTRING_INDEX(SUBSTRING_INDEX(@@VERSION,'.', -2), '.', -1) AS patch;
but that isn't entirely satisfactory (e.g. see
-log) and it doesn't directly check the existence of the feature.
Is anyone aware of better ways?
<edit: To amend Rick's answer a bit, the comments syntax can be used to recognize constructs too, not just versions. For instance, in this particular case like this
SELECT /*!JSON_TYPE*/('["a", "b", 1]');. Here's a link to the documentation: http://dev.mysql.com/doc/refman/5.7/en/comments.html.