Type Conversion

Data type conversion can be useful for converting input type for SQL functions or when outputting a different format than the stored data type.

Data conversion can result in data loss if you try to fit a value from a larger data type to a smaller data type, or if you convert values between different data types.

Cast

Converts 'x' to the 't' data type.

Parameters:

  • from - from data value
  • target - target data type

Usage:

  • cast(from AS target)

Returns:

  • target data type

parseDateTimeBestEffort

Parse a string to a date or datetime type. Can process more complex date formats than toDate and toDateTime. Failure handling versions are also available for each i.e parseDateTimeBestEffortOrZero & parseDateTimeBestEffortOrNull.

Parameters:

  • string - date string format

Usage:

  • parseDateTimeBestEffort(string)

Returns:

  • DateTime if sucessful
  • null or 0 with failure handling versions

toDateTime

Converts an input value to the datetime data type. Failure handling versions are also available for each i.e toDateTimeOrZero & toDateTimeOrNull.

Parameters:

  • string - date string format

Usage:

  • toDateTime(string)

Returns:

  • DateTime if successful
  • null or 0 with failure handling versions

toDate

Converts an input value to the date data type. Failure handling versions are also available for each i.e toDateOrZero & toDateOrNull.

Parameters:

  • string - date string format

Usage:

  • toDate(string)

Returns:

  • Date if successful
  • null or 0 with failure handling versions

toDecimal 32|64|128

Converts an input value to the Decimal data type with a precision of S. Failure handling version are also available for each i.e toDecimal32OrZero & toDecimal32OrNull.

Parameters:

  • exp - number or numerical string
  • s - number of decimal places

Usage:

  • toDecimal32(exp, s)
  • toDecimal64(exp, s)

Returns:

  • Decimal32|Decimal64 if successful
  • null or 0 with failure handling versions

toFloat 32|64

Converts an input value to the Float data type. Failure handling version are also available for each i.e toFloat32OrZero & toFloat32OrNull.

Parameters:

  • exp - number or numerical string

Usage:

  • toFloat32(exp)
  • toFloat64(exp)

Returns:

  • Float32|Float64 if successful
  • null or 0 with failure handling versions

toInt 8|16|32|64

Converts an input value to the Int data type. Failure handling versions are also available for each i.e toInt8OrZero & toInt8OrNull.

Parameters:

  • exp - number or numerical string

Usage:

  • toInt8(exp)
  • toInt16(exp)
  • toInt32(exp)
  • toInt64(exp)

Returns:

  • Int8|Int16|Int32|Int64 if successful
  • null or 0 with failure handling versions

toUInt

Converts an input value to the UInt data type. If you pass a negative string value an exception is raised. Failure handling version are also available for each i.e toUInt8OrZero & toUInt8OrNull.

Parameters:

  • exp - number or numerical string

Usage:

  • toUInt8(exp)
  • toUInt16(exp)
  • toUInt32(exp)
  • toUInt64(exp)

Returns:

  • UInt8|UInt16|UInt32|UInt64 if successful
  • null or 0 with failure handling versions

toInterval Year|Quarter|Month|Week|Day|Hour|Minute|Second

Converts a Number type argument to an Interval data type.

Parameters:

  • n - interval number

Usage:

  • toIntervalYear(n)
  • toIntervalMonth(n)
  • toIntervalQuarter(n)
  • toIntervalWeek(n)
  • toIntervalDay(n)
  • toIntervalMinute(n)
  • toIntervalSecond(n)

Returns:

  • Interval

toString

Converts between numbers, strings, dates, and dates with times. The toString of the DateTime argument can take a second String argument containing the name of the time zone.

Parameters:

  • t - the target type
  • timezone (Optional) - timezone string when target is a date time value

Usage:

  • toString(t)
  • toString(t, timezone)

Returns:

  • String

toTypeName

Returns the type name of the passed argument.

Parameters:

  • t - the target type value

Usage:

  • toTypeName(t)

Returns:

  • String

toUUID

Converts a UUID represented as a String to a UUID data type

Parameters:

  • string_uuid - a String representation of a UUID

Usage:

toUUID(string_uuid)

Returns:

  • UUID

UUIDNumToString

Converts a UUID represented as a FixedString(16) type in binary format to a String.

Parameters:

  • num_uuid - a FixedString(16) representation of a UUID

Usage:

UUIDNumToString(num_uuid)

Returns:

  • String

UUIDStringToNum

Converts a UUID represented as a String type to a FixedString(16) in binary format.

Parameters:

  • string_uuid - a String representation of a UUID

Usage:

UUIDStringToNum(string_uuid)

Returns:

  • String

Did this page help you?