Type Conversions
Data types may be converted from one form to another either explicitly or implicitly. Implicit conversions automatically occur in criteria and expressions to ease development. Explicit data type conversions require the use of the CONVERT
function or CAST
keyword.
Type conversion considerations:
- Any type may be implicitly converted to the
OBJECT
type; - The
OBJECT
type may be explicitly converted to any other type; - The
NULL
value may be converted to any type; - Any valid implicit conversion is also a valid explicit conversion;
- Situations involving literal values that would normally require explicit conversions may have the explicit conversion applied implicitly if no loss of information occurs;
When the CData Virtuality Server detects that an explicit conversion cannot be applied implicitly in criteria, the criteria will be treated as false. For example:
SQLSELECT * FROM my.table WHERE created_by = 'not a date'
Given that
created_by
is typed as date, rather than converting 'not a date' to a date value, the criteria will remain as a string comparison and therefore beFALSE
;- Explicit conversions that are not allowed between two types will result in an exception before execution. Allowed explicit conversions may still fail during processing if the runtime values are not convertible.
The CData Virtuality Server conversions of float
/double
/bigdecimal
/timestamp
to string
rely on the JDBC/Java-defined output formats. Pushdown behaviour attempts to mimic these results but may vary depending on the source type and conversion logic. Care should be taken not to assume the string form in criteria or other places where a variation may cause different results.
Type Conversions
Source type | Valid implicit target types | Valid explicit target types |
---|---|---|
|
|
|
|
| - |
|
| - |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| - |
|
| - |
|
| date , time |
| string | - |
| - |
|