> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TRY_CAST

> Converts a value to a requested SQL type and returns NULL for failed supported conversions.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Scalar function</span></div>

A NULL value remains NULL for a supported conversion. A failed supported value conversion produces NULL.

## Syntax

### Scalar

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
try_cast(value AS target_type)
```

## Arguments

| Name | Type | Required | Description |
| - | - | - | - |
| value | BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY, MAP or STRUCT or VARIANT | Yes | Value to convert. Source and target must form a supported conversion pair; listing a source type does not permit conversion to every target. See the conversion restrictions below. For DECIMAL(p, s), p is precision (total digits) and s is scale (digits after the decimal point). |
| target\_type | SQL type specification | Yes | Requested target type. Specify BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME or TIMESTAMP. ARRAY, MAP and STRUCT targets require complete nested type definitions and do not perform recursive element conversion. The source/target pair must be a supported conversion. Must be a constant argument. |

## Returns

* Type: Requested target SQL type
* NULL behavior: A NULL value remains NULL for a supported conversion. A failed supported value conversion produces NULL.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | No |
| Exact result | Partial (Conversions can truncate, round or replace invalid encoding; not every conversion preserves the input value exactly.) |

## Usage notes

* Write the target type directly in the call. It cannot be a STRING expression that changes for each row.
* INTEGER and INT mean the same type; STRING means VARCHAR text. NULL can be used with a supported type. Cast NULL explicitly when its type would otherwise be unclear.
* Not every source type can be converted to every target type. MAP-to-STRING and STRUCT-to-STRING conversions are rejected. Casting ARRAY, MAP, or STRUCT does not recursively convert its elements or fields.
* Deterministic: The same inputs and settings produce the same result.

## Examples

### Typical behavior

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT TRY_CAST('42' AS INT) AS "value", TRY_CAST(CAST(NULL AS STRING) AS INT) AS null_value;
```

| value | null\_value |
| - | - |
| 42 | NULL |

### Handle invalid values in different target types

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT TRY_CAST('12.50' AS DECIMAL(8,2)) AS price, TRY_CAST('not-a-date' AS DATE) AS invalid_date;
```

| price | invalid\_date |
| - | - |
| 12.50 | NULL |

## Limitations

* Unsupported conversions or incomplete target-type definitions can cause the query to be rejected before execution. TRY\_CAST does not turn those errors into NULL.
* CHAR and VARCHAR length limits are not enforced by this cast. Do not rely on the cast to truncate text.

## Related functions

* [typeof](/query/sql/functions/conditional/typeof)
* [cast](/query/sql/functions/conditional/cast)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.