Data Types in MySQL
Date: 17 Nov 2014 09:53:44 GMT
Message-ID: <MySQL-20141117102943_at_ram.dialup.fu-berlin.de>
In programming languages, a function parameter often has a data type. The argument then must have the same type.
In the MySQL documentation, I can read:
ACOS(X)
Returns the arc cosine of X, that is, the value whose cosine is X. Returns NULL if X is not in the range -1 to 1.
But nowhere does it says something about the type of X.
SELECT ACOS( '0' );
+--------------------+
| ACOS( '0' ) |
+--------------------+
| 1.5707963267948966 |
+--------------------+
»'0'« is a string. ACOS accepts it without a warning.
Where can one read in the documentation about the rules leading to this behavior? Where does the documentation say that such a string literal is allowed when a number X is expected?
CREATE TABLE T( F INTEGER );
INSERT INTO T ( F )VALUES ( '1.2' );
Query OK, 1 row affected
I have declared a column as »INTEGER«. Then, I have inserted a value that is a string which contains numeral with a point.
When someone inserts »'1.2'« into a place where an integer like »1« is expected, many programming languages believe that he might have some false assumptions about the nature of that place and deserves at least a warning.
I also tried setting SQL_MODE to various values, including STRICT_ALL_TABLES, TRADITIONAL, and ANSI. But this does not seem to change that behavior.
Is there a documentation that states the type of literals (such as »1«, »1.2«, »'1'«, »'1.2'«, »'abc'«)?¹
Is there a documentation that states the type of expressions, the type of parameters and the rules governing which type is allowed in a value list in the INSERT-INTO query for a column with a certain type, and which type is allowed for the argument of a certain built-in function?
Or what are the rules/restrictions for arguments of inbuilt functions and values to be inserted in columns?
1 The section »MySQL 5.0 Reference Manual :: 9 Language Structure :: 9.1 Literal Values :: 9.1.1 String Literals« calls string literals »string literals« but does not explicitly say that they have a type and that this type is »string«. Received on Mon Nov 17 2014 - 10:53:44 CET