Implicit value conversion
Previous  Next

When an operator is used with operands of different types, type conversion implicitly occurs to make the operands compatible. For example, numbers are converted to strings as necessary, and vice versa.

Note: explicit conversions (using the CAST function) are not yet available

The following table describes how conversion occurs for comparison operations:
  
Left
Right
Cast as
NULL evaluation
VARCHAR
INTEGER
VARCHAR
-
VARCHAR
DOUBLE
VARCHAR
-
VARCHAR
NULL
VARCHAR
$right = ''
INTEGER
VARCHAR
VARCHAR
-
INTEGER
DOUBLE
DOUBLE
-
INTEGER
NULL
INTEGER
$right = 0
DOUBLE
VARCHAR
VARCHAR
-
DOUBLE
INTEGER
DOUBLE
-
DOUBLE
NULL
DOUBLE
$right = 0.0
NULL
VARCHAR
VARCHAR
$left = ''
NULL
INTEGER
INTEGER
$left = 0
NULL
DOUBLE
DOUBLE
$left = 0.0
NULL
NULL
VARCHAR
$left = '', $right = ''

Some more notes about comparison:

·      NULL = NULL, NULL = 0 and NULL = '' (and vice-versa) are always evaluated to true
·      the DATE, TIME, DATETIME and TIMESTAMP data types are internally mapped to TIMESTAMP and their comparisons occur like for INTEGER types
·      comparisons that use floating-point numbers (or values that are converted to floating-point numbers) are approximate because such numbers are inexact and usually have only 53 bits of precision and are subject to rounding
·      the conversion from string to floating-point and from integer to floating-point do not necessarily occur the same way. The integer may be converted to floating-point by the CPU, whereas the string is converted digit by digit in an operation that involves floating- point multiplications.