mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-28 18:42:26 +00:00
New syntax added and the beginning is edited.
This commit is contained in:
parent
f45869ab44
commit
f56d1563b7
@ -465,27 +465,29 @@ Result:
|
|||||||
|
|
||||||
## CAST(x, T) {#type_conversion_function-cast}
|
## CAST(x, T) {#type_conversion_function-cast}
|
||||||
|
|
||||||
Converts input value `x` to the `T` data type. Unlike to `reinterpret` function, type conversion is performed in a natural way.
|
Converts an input value to a specified data type. Unlike the [reinterpret](#type_conversion_function-reinterpret) function, type conversion is performed in a natural way. If conversion can not be done then an exception is raised.
|
||||||
|
Several syntax variants are supported.
|
||||||
The syntax `CAST(x AS t)` is also supported.
|
|
||||||
|
|
||||||
!!! note "Note"
|
|
||||||
If value `x` does not fit the bounds of type `T`, the function overflows. For example, `CAST(-1, 'UInt8')` returns `255`.
|
|
||||||
|
|
||||||
**Syntax**
|
**Syntax**
|
||||||
|
|
||||||
``` sql
|
``` sql
|
||||||
CAST(x, T)
|
CAST(x, T)
|
||||||
|
CAST(x AS t)
|
||||||
|
x::t
|
||||||
```
|
```
|
||||||
|
|
||||||
**Arguments**
|
**Arguments**
|
||||||
|
|
||||||
- `x` — Any type.
|
- `x` — A value to convert. May be of any type.
|
||||||
- `T` — Destination type. [String](../../sql-reference/data-types/string.md).
|
- `T` — The name of the target data type. [String](../../sql-reference/data-types/string.md).
|
||||||
|
- `t` — The target data type.
|
||||||
|
|
||||||
**Returned value**
|
**Returned value**
|
||||||
|
|
||||||
- Destination type value.
|
- Converted value.
|
||||||
|
|
||||||
|
!!! note "Note"
|
||||||
|
If the input value does not fit the bounds of the target type, the result overflows. For example, `CAST(-1, 'UInt8')` returns `255`.
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
@ -494,14 +496,14 @@ Query:
|
|||||||
```sql
|
```sql
|
||||||
SELECT
|
SELECT
|
||||||
CAST(toInt8(-1), 'UInt8') AS cast_int_to_uint,
|
CAST(toInt8(-1), 'UInt8') AS cast_int_to_uint,
|
||||||
CAST(toInt8(1), 'Float32') AS cast_int_to_float,
|
CAST(1.5 AS Int32) AS cast_float_to_int,
|
||||||
CAST('1', 'UInt32') AS cast_string_to_int;
|
'1'::Int32 AS cast_string_to_int;
|
||||||
```
|
```
|
||||||
|
|
||||||
Result:
|
Result:
|
||||||
|
|
||||||
```
|
```
|
||||||
┌─cast_int_to_uint─┬─cast_int_to_float─┬─cast_string_to_int─┐
|
┌─cast_int_to_uint─┬─cast_float_to_int─┬─cast_string_to_int─┐
|
||||||
│ 255 │ 1 │ 1 │
|
│ 255 │ 1 │ 1 │
|
||||||
└──────────────────┴───────────────────┴────────────────────┘
|
└──────────────────┴───────────────────┴────────────────────┘
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user