Convert a value from one data type to another.
Explicitly converts a value from one data type to another, failing at runtime if the conversion is not possible. Preferred over implicit conversion for clarity and to avoid engine-specific coercion behaviors. Equivalent to double-colon syntax in PostgreSQL.
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | ✓ Supported | all | CAST(expr AS type). Also CONVERT(expr, type). Supports a limited set of target types (CHAR, SIGNED, UNSIGNED, DATE, DATETIME, DECIMAL, JSON, BINARY). |
| PostgreSQL | ✓ Supported | all | CAST(expr AS type). Also :: shorthand cast operator (expr::type) which is very commonly used in practice and works anywhere an expression is valid. |
| SQL Server | ✓ Supported | all | CAST(expr AS type). Also CONVERT(type, expr [, style]) which adds optional style codes for date/number formatting. |
| Oracle | ✓ Supported | all | CAST standard. TO_DATE(), TO_NUMBER(), TO_CHAR() are the traditional Oracle conversion functions for common types. |
| SQLite | ✓ Supported | all | CAST(expr AS type). SQLite uses flexible type affinity; CAST influences storage affinity rather than strictly enforcing types. |
CAST is SQL-standard. PostgreSQL's :: shorthand is unique and extremely common in practice. SQL Server's CONVERT adds format-style codes useful for date/number display.
CAST(expr AS type). Also CONVERT(expr, type). Supports a limited set of target types (CHAR, SIGNED, UNSIGNED, DATE, DATETIME, DECIMAL, JSON, BINARY).
CAST(expr AS type). Also :: shorthand cast operator (expr::type) which is very commonly used in practice and works anywhere an expression is valid.
CAST(expr AS type). Also CONVERT(type, expr [, style]) which adds optional style codes for date/number formatting.
CAST standard. TO_DATE(), TO_NUMBER(), TO_CHAR() are the traditional Oracle conversion functions for common types.
CAST(expr AS type). SQLite uses flexible type affinity; CAST influences storage affinity rather than strictly enforcing types.