---
title: Cast values to different types
description: 'Use the CAST function or double-colon :: casting shorthand syntax to cast a value to a specific type.'
url: https://docs.influxdata.com/influxdb3/enterprise/query-data/sql/cast-types/
estimated_tokens: 1770
product: InfluxDB 3 Enterprise
version: enterprise
publisher: InfluxData
canonical: https://docs.influxdata.com/influxdb3/enterprise/query-data/sql/cast-types/
date: '2025-01-23T10:18:45-07:00'
lastmod: '2025-01-23T10:18:45-07:00'
---

Use the `CAST` function or double-colon `::` casting shorthand syntax to cast a
value to a specific type.

```sql
-- CAST function
SELECT CAST(1234.5 AS BIGINT)

-- Double-colon casting shorthand
SELECT 1234.5::BIGINT
```

* [Cast to a string type](#cast-to-a-string-type)
* [Cast to numeric types](#cast-to-numeric-types)
  * [Float](#cast-to-a-float)
  * [Integer](#cast-to-an-integer)
  * [Unsigned integer](#cast-to-an-unsigned-integer)

* [Cast to a boolean type](#cast-to-a-boolean-type)
* [Cast to a timestamp type](#cast-to-a-timestamp-type)

Casting operations can be performed on a column expression or a literal value.
For example, the following query uses the[Home sensor sample data](/influxdb3/enterprise/reference/sample-data/#home-sensor-data)and:

* Casts all values in the `time` column to integers (Unix nanosecond timestamps).
* Casts the literal string value `'1234'` to a 64-bit float for each row.

#### :: shorthand ####

```sql
SELECT
  time::BIGINT AS unix_time,
  '1234'::DOUBLE AS string_to_float
FROM home
LIMIT 5
```

```sql
SELECT
  CAST(time AS BIGINT) AS unix_time,
  CAST('1234' AS DOUBLE) AS string_to_float
FROM home
LIMIT 5
```

|    unix\_time     |string\_to\_float|
|-------------------|-----------------|
|1641024000000000000|      1234       |
|1641027600000000000|      1234       |
|1641031200000000000|      1234       |
|1641034800000000000|      1234       |
|1641038400000000000|      1234       |

## Cast to a string type

Use the `STRING`, `CHAR`, `VARCHAR`, or `TEXT` type in a casting operation to
cast a value to a string.

#### :: shorthand ####

```sql
value::STRING
value::CHAR
value::VARCHAR
value::TEXT
```

```sql
CAST(value AS STRING)
CAST(value AS CHAR)
CAST(value AS VARCHAR)
CAST(value AS TEXT)
```

SQL supports casting the following to a string value:

* **Floats**
* **Integers**
* **Unsigned integers**
* **Booleans**
* **Timestamps**

## Cast to numeric types

The InfluxDB SQL implementation supports 64-bit floats (`DOUBLE`),
integers (`BIGINT`), and unsigned integers (`BIGINT UNSIGNED`).

### Cast to a float

Use the `DOUBLE` type in a casting operation to cast a value to a 64-bit float.

#### :: shorthand ####

```sql
value::DOUBLE
```

```sql
CAST(value AS DOUBLE)
```

SQL supports casting the following to a float value:

* **Strings**: Returns the float equivalent of the numeric string (`[0-9]`).
  The following string patterns are also supported:

  * Scientific notation (`'123.4E+10'`)
  * Infinity (`'±Inf'`)
  * NaN (`'NaN'`)

* **Integers**

* **Unsigned integers**

### Cast to an integer

Use the `BIGINT` type in a casting operation to cast a value to a 64-bit signed integer.

#### :: shorthand ####

```sql
value::BIGINT
```

```sql
CAST(value AS BIGINT)
```

SQL supports casting the following to an integer:

* **Strings**: Returns the integer equivalent of the numeric string (`[0-9]`).
* **Floats**: Truncates the float value at the decimal.
* **Unsigned integers**: Returns the signed integer equivalent of the unsigned integer.
* **Booleans**: Returns `1` for `true` and `0` for `false`.
* **Timestamps**: Returns the equivalent[nanosecond epoch timestamp](/influxdb3/enterprise/reference/glossary/#unix-timestamp).

### Cast to an unsigned integer

Use the `BIGINT UNSIGNED` type in a casting operation to cast a value to a
64-bit unsigned integer.

#### :: shorthand ####

```sql
value::BIGINT UNSIGNED
```

```sql
CAST(value AS BIGINT UNSIGNED)
```

SQL supports casting the following to an unsigned integer:

* **Strings**: Returns the unsigned integer equivalent of the numeric string (`[0-9]`).
* **Floats**: Truncates the float value at the decimal.
* **Integers**: Returns the unsigned integer equivalent of the signed integer.
* **Booleans**: Returns `1` for `true` and `0` for `false`.
* **Timestamps**: Returns the equivalent[nanosecond epoch timestamp](/influxdb3/enterprise/reference/glossary/#unix-timestamp).

## Cast to a boolean type

Use the `BOOLEAN` type in a casting operation to cast a value to a boolean.

#### :: shorthand ####

```sql
value::BOOLEAN
```

```sql
CAST(value AS BOOLEAN)
```

SQL supports casting the following to a boolean:

* **Strings**
  * Return `true`:
    * `'true'` *(case-insensitive)*
    * `'t'`, *(case-insensitive)*
    * `'1'`

  * Return `false`:
    * `'false'` *(case-insensitive)*
    * `'f'` *(case-insensitive)*
    * `'0'`

* **Integers**
  * Returns `true`: positive non-zero integer
  * Returns `false`: `0`

* **Unsigned integers**
  * Returns `true`: non-zero unsigned integer
  * Returns `false`: `0`

## Cast to a timestamp type

Use the `TIMESTAMP` type in a casting operation to cast a value to a timestamp.

#### :: shorthand ####

```sql
value::TIMESTAMP
```

```sql
CAST(value AS TIMESTAMP)
```

SQL supports casting the following to a timestamp:

* **Strings**: Returns the timestamp equivalent of the string value.
  The following RFC3339 and RFC339-like string patterns are supported:

  * `YYYY-MM-DDT00:00:00.000Z`
  * `YYYY-MM-DDT00:00:00.000-00:00`
  * `YYYY-MM-DD 00:00:00.000-00:00`
  * `YYYY-MM-DDT00:00:00Z`
  * `YYYY-MM-DD 00:00:00.000`
  * `YYYY-MM-DD 00:00:00`
  * `YYYY-MM-DD`

* **Integers**: Parses the integer as a Unix *second* timestamp and returns
  the equivalent timestamp.

* **Unsigned integers**: Parses the unsigned integer as a Unix nanosecond timestamp
  and returns the equivalent timestamp.

#### Cast Unix nanosecond timestamps to a timestamp type

To cast a Unix nanosecond timestamp to a timestamp type, first cast the numeric
value to an unsigned integer (`BIGINT UNSIGNED`) and then a timestamp.
You can also use the [`to_timestamp_nanos`](/influxdb3/enterprise/reference/sql/functions/time-and-date/\> #to\_timestamp\_nanos)
function.

#### :: shorthand ####

```sql
1704067200000000000::BIGINT UNSIGNED::TIMESTAMP
```

```sql
CAST(CAST(1704067200000000000 AS BIGINT UNSIGNED) AS TIMESTAMP)
```

```sql
to_timestamp_nanos(1704067200000000000)
```

### Timestamp functions

You can also use the following SQL functions to cast a value to a timestamp type:

* [`to_timestamp`](/influxdb3/enterprise/reference/sql/functions/time-and-date/#to_timestamp)
* [`to_timestamp_millis`](/influxdb3/enterprise/reference/sql/functions/time-and-date/#to_timestamp_millis)
* [`to_timestamp_micros`](/influxdb3/enterprise/reference/sql/functions/time-and-date/#to_timestamp_micros)
* [`to_timestamp_nanos`](/influxdb3/enterprise/reference/sql/functions/time-and-date/#to_timestamp_nanos)
* [`to_timestamp_seconds`](/influxdb3/enterprise/reference/sql/functions/time-and-date/#to_timestamp_seconds)
* [to\_unixtime](/influxdb3/enterprise/reference/sql/functions/time-and-date/#to_unixtime)

#### Related

* [SQL data types](/influxdb3/enterprise/reference/sql/data-types/)

[query](/influxdb3/enterprise/tags/query/)[sql](/influxdb3/enterprise/tags/sql/)
| unix_time | string_to_float |
| --- | --- |
| unix_time | string_to_float |
| 1641024000000000000 | 1234 |
| 1641027600000000000 | 1234 |
| 1641031200000000000 | 1234 |
| 1641034800000000000 | 1234 |
| 1641038400000000000 | 1234 |
