Outdated Version

You are viewing an older version of this section. View current production version.

CONVERT

Casts the input to the given datatype. There is usually no visible effect on the printed value; what changes is the rules for comparison and sorting.

CONVERT (input, {BINARY | CHAR | DATE | DATETIME[(prec)] | DECIMAL[(prec [, scale])] | TIME[(prec)] | SIGNED [INTEGER] | UNSIGNED [INTEGER]})
CAST (input AS {BINARY | CHAR | DATE | DATETIME[(prec)] | DECIMAL[(prec [, scale])] | TIME[(prec)] | SIGNED [INTEGER] | UNSIGNED [INTEGER]})

Return Type

The converted object.

Examples

memsql> select convert(-123, UNSIGNED);
+-------------------------+
| convert(-123, UNSIGNED) |
+-------------------------+
|    18446744073709551493 |
+-------------------------+

memsql> select '2019-01-01', cast('2019-01-01' AS TIME);
+------------+----------------------------+
| 2019-01-01 | cast('2019-01-01' AS TIME) |
+------------+----------------------------+
| 2019-01-01 | 00:20:19                   |
+------------+----------------------------+