Conversion Functions

This section provides reference information for the conversion functions in PlaidCloud Lakehouse.

Please note the following when converting a value from one type to another:

  • When converting from floating-point, decimal numbers, or strings to integers or decimal numbers with fractional parts, PlaidCloud Lakehouse rounds the values to the nearest integer. This is determined by the setting numeric_cast_option (defaults to 'rounding') which controls the behavior of numeric casting operations. When numeric_cast_option is explicitly set to 'truncating', PlaidCloud Lakehouse will truncate the decimal part, discarding any fractional values.

    SELECT CAST('0.6' AS DECIMAL(10, 0)), CAST(0.6 AS DECIMAL(10, 0)), CAST(1.5 AS INT);
    
    ┌──────────────────────────────────────────────────────────────────────────────────┐
     cast('0.6' as decimal(10, 0))  cast(0.6 as decimal(10, 0))  cast(1.5 as int32) 
    ├───────────────────────────────┼─────────────────────────────┼────────────────────┤
                                 1                            1                   2 
    └──────────────────────────────────────────────────────────────────────────────────┘
    
    SET numeric_cast_option = 'truncating';
    
    SELECT CAST('0.6' AS DECIMAL(10, 0)), CAST(0.6 AS DECIMAL(10, 0)), CAST(1.5 AS INT);
    
    ┌──────────────────────────────────────────────────────────────────────────────────┐
     cast('0.6' as decimal(10, 0))  cast(0.6 as decimal(10, 0))  cast(1.5 as int32) 
    ├───────────────────────────────┼─────────────────────────────┼────────────────────┤
                                 0                            0                   1 
    └──────────────────────────────────────────────────────────────────────────────────┘
    

    The table below presents a summary of numeric casting operations, highlighting the casting possibilities between different source and target numeric data types. Please note that, it specifies the requirement for String to Integer casting, where the source string must contain an integer value.

    Source TypeTarget Type
    StringDecimal
    FloatDecimal
    DecimalDecimal
    FloatInt
    DecimalInt
    String (Int)Int
  • PlaidCloud Lakehouse also offers a variety of functions for converting expressions into different date and time formats. For more information, see Date & Time Functions.


BUILD_BITMAP

Learn how to use the BUILD_BITMAP conversion function in PlaidCloud Lakehouse. Converts an array of positive integers to a BITMAP value. Includes syntax and...

CAST, ::

Learn how to use the CAST, :: conversion function in PlaidCloud Lakehouse. Converts a value from one data type to another. Includes syntax and examples.

TO_BINARY

Learn how to use the TO_BINARY conversion function in PlaidCloud Lakehouse. Converts supported data types, including string, variant, bitmap, geometry, and...

TO_BITMAP

Learn how to use the TO_BITMAP conversion function in PlaidCloud Lakehouse. Converts a value to BITMAP data type. Includes syntax and examples.

TO_BOOLEAN

Learn how to use the TO_BOOLEAN conversion function in PlaidCloud Lakehouse. Converts a value to BOOLEAN data type. Includes syntax and examples.

TO_FLOAT32

Learn how to use the TO_FLOAT32 conversion function in PlaidCloud Lakehouse. Converts a value to FLOAT32 data type. Includes syntax and examples.

TO_FLOAT64

Learn how to use the TO_FLOAT64 conversion function in PlaidCloud Lakehouse. Converts a value to FLOAT64 data type. Includes syntax and examples.

TO_HEX

Learn how to use the TO_HEX conversion function in PlaidCloud Lakehouse. For a string argument str, TO_HEX() returns a hexadecimal string representation of...

TO_INT16

Learn how to use the TO_INT16 conversion function in PlaidCloud Lakehouse. Converts a value to INT16 data type. Includes syntax and examples.

TO_INT32

Learn how to use the TO_INT32 conversion function in PlaidCloud Lakehouse. Converts a value to INT32 data type. Includes syntax and examples.

TO_INT64

Learn how to use the TO_INT64 conversion function in PlaidCloud Lakehouse. Converts a value to INT64 data type. Includes syntax and examples.

TO_INT8

Learn how to use the TO_INT8 conversion function in PlaidCloud Lakehouse. Converts a value to INT8 data type. See syntax and usage examples.

TO_STRING

Learn how to use the TO_STRING conversion function in PlaidCloud Lakehouse. Converts a value to String data type, or converts a Date value to a specific...

TO_TEXT

Learn how to use TO_TEXT in PlaidCloud Lakehouse. Alias for the TO_STRING conversion function. Includes detailed syntax, examples, and usage reference.

TO_UINT16

Learn how to use the TO_UINT16 conversion function in PlaidCloud Lakehouse. Converts a value to UINT16 data type. Includes syntax and examples.

TO_UINT32

Learn how to use the TO_UINT32 conversion function in PlaidCloud Lakehouse. Converts a value to UINT32 data type. Includes syntax and examples.

TO_UINT64

Learn how to use the TO_UINT64 conversion function in PlaidCloud Lakehouse. Converts a value to UINT64 data type. Includes syntax and examples.

TO_UINT8

Learn how to use the TO_UINT8 conversion function in PlaidCloud Lakehouse. Converts a value to UINT8 data type. Includes syntax and examples.

TO_VARCHAR

Learn how to use TO_VARCHAR in PlaidCloud Lakehouse. Alias for the TO_STRING conversion function. Includes detailed syntax, examples, and usage reference.

TO_VARIANT

Learn how to use the TO_VARIANT conversion function in PlaidCloud Lakehouse. Converts a value to VARIANT data type. Includes syntax and examples.

TRY_CAST

Learn how to use the TRY_CAST conversion function in PlaidCloud Lakehouse. Converts a value from one data type to another. Includes syntax and examples.

TRY_TO_BINARY

Learn how to use the TRY_TO_BINARY conversion function in PlaidCloud Lakehouse. An enhanced version of TO_BINARY that converts an input expression to a...