From ca36c08f6aecc931cafff32f42c702043834b80f Mon Sep 17 00:00:00 2001 From: Soeren Wolfers Date: Sun, 1 Dec 2024 18:02:42 +0000 Subject: [PATCH 1/2] Update typecasting.md --- docs/sql/data_types/typecasting.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/sql/data_types/typecasting.md b/docs/sql/data_types/typecasting.md index 587930eb01f..94ec1550e5b 100644 --- a/docs/sql/data_types/typecasting.md +++ b/docs/sql/data_types/typecasting.md @@ -12,11 +12,17 @@ Explicit typecasting is performed by using a `CAST` expression. For example, `CA ## Implicit Casting -In many situations, the system will add casts by itself. This is called *implicit* casting. This happens for example when a function is called with an argument that does not match the type of the function, but can be casted to the desired type. +When a function is called with an argument that does not match the type of the function, but can be casted to the desired type, the system will add an *implicit* cast. + +Implicit casts can only be added for a number of type combinations, and is generally only possible when the cast cannot fail. For example, an implicit cast can be added from `INTEGER` to `DOUBLE` – but not from `DOUBLE` to `INTEGER`. Consider the function `sin(DOUBLE)`. This function takes as input argument a column of type `DOUBLE`, however, it can be called with an integer as well: `sin(1)`. The integer is converted into a double before being passed to the `sin` function. -Implicit casts can only be added for a number of type combinations, and is generally only possible when the cast cannot fail. For example, an implicit cast can be added from `INTEGER` to `DOUBLE` – but not from `DOUBLE` to `INTEGER`. +### Combination casting + +When values of different types need to be combined to an unspecified joint parent type, the system will perform implicit casts to an automatically selected parent type. The implicit casts performed in this situation are more lenient than regular implicit casts; for example, a `BOOL` value may be cast to `INT` (with `true` mapping to `1` and `false` to `0`) even though this is not possible for regular implicit casts. + +This *combination casting* occurs for comparisons (`==` / `<` / `>`), set operations (`UNION` / `EXCEPT` / `INTERSECT`), and nested type constructors (`list_value` / `[...]` / `MAP`). ## Casting Operations Matrix From 282228cb9aae776409cdd5f226d2d85ceb42f069 Mon Sep 17 00:00:00 2001 From: Soeren Wolfers Date: Sun, 1 Dec 2024 18:10:47 +0000 Subject: [PATCH 2/2] Update typecasting.md --- docs/sql/data_types/typecasting.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sql/data_types/typecasting.md b/docs/sql/data_types/typecasting.md index 94ec1550e5b..0c10b4a21a6 100644 --- a/docs/sql/data_types/typecasting.md +++ b/docs/sql/data_types/typecasting.md @@ -12,7 +12,7 @@ Explicit typecasting is performed by using a `CAST` expression. For example, `CA ## Implicit Casting -When a function is called with an argument that does not match the type of the function, but can be casted to the desired type, the system will add an *implicit* cast. +In many situations, the system will add casts by itself. This is called *implicit* casting and happens, for example, when a function is called with an argument that does not match the type of the function but can be casted to the required type. Implicit casts can only be added for a number of type combinations, and is generally only possible when the cast cannot fail. For example, an implicit cast can be added from `INTEGER` to `DOUBLE` – but not from `DOUBLE` to `INTEGER`. @@ -20,7 +20,7 @@ Consider the function `sin(DOUBLE)`. This function takes as input argument a col ### Combination casting -When values of different types need to be combined to an unspecified joint parent type, the system will perform implicit casts to an automatically selected parent type. The implicit casts performed in this situation are more lenient than regular implicit casts; for example, a `BOOL` value may be cast to `INT` (with `true` mapping to `1` and `false` to `0`) even though this is not possible for regular implicit casts. +When values of different types need to be combined to an unspecified joint parent type, the system will perform implicit casts to an automatically selected parent type. For example, `list_value(1::INT64, 1::UINT64)` creates a list of type `INT128[]`. The implicit casts performed in this situation are sometimes more lenient than regular implicit casts. For example, a `BOOL` value may be cast to `INT` (with `true` mapping to `1` and `false` to `0`) even though this is not possible for regular implicit casts. This *combination casting* occurs for comparisons (`==` / `<` / `>`), set operations (`UNION` / `EXCEPT` / `INTERSECT`), and nested type constructors (`list_value` / `[...]` / `MAP`).