Reputation: 2336
How would I write an IF
... THEN
... ELSE
within MySQL where my IF is testing for the server version number? Pointers to the correct section of the docs are appreciated. More details are really appreciated.
Update:
Apologies for an unintentionally vague question.
I keep a sql script ready to create databases and users easily when I deploy something on machines (new to me). Different servers are running different versions of the software and I wanted to make the script reliable and version-aware.
Upvotes: 2
Views: 947
Reputation: 562368
It's hard to answer this because you haven't described what you're trying to do, but you may like to know about a neat feature of MySQL SQL comment syntax to make some parts of a query version-dependent.
See http://dev.mysql.com/doc/refman/5.7/en/comments.html
If you add a version number after the “!” character, the syntax within the comment is executed only if the MySQL version is greater than or equal to the specified version number. The TEMPORARY keyword in the following comment is executed only by servers from MySQL 3.23.02 or higher:
CREATE /*!32302 TEMPORARY */ TABLE t (a INT);
Upvotes: 2
Reputation: 4350
Ej: (mayor version number, from '5.6.26-74.0-log'
extracts '5'
)
SELECT SUBSTRING( @@VERSION , 1 , LOCATE( '.' , @@VERSION ) )
Upvotes: 0