---
title: "CAST in Strata | Oplema"
description: "Convert a value to another data type; invalid conversions raise an error. Write it as CAST(expr AS type) in a Strata Formula or Filter."
url: "https://oplema.com/docs/strata/functions/cast"
updated: "2026-11-04"
---

# CAST

Convert a value to another data type; invalid conversions raise an error.

## Try an expression

In [Formula](https://oplema.com/docs/strata/prep/formula), enter the expression and set Output type to **VARCHAR**.

Example input

1. Row 1 `amount = 20`
2. Row 2 `amount = 120`
3. Row 3 `amount = NULL`

### Expression

```
CAST(amount AS VARCHAR)
```

### Result

```
Row 1: '20'
Row 2: '120'
Row 3: NULL
```

NULL means the value is missing.

Try it live in Formula

Result
| id | amount | result |
| --- | --- | --- |
| 1 | 20 | 20 |
| 2 | 120 | 120 |
| 3 |  |  |

## Arguments and types

```
CAST(expr AS type)
```

The result type can depend on the input types. See DuckDB for the full argument rules.

## Things to know

### Formula output conversion

For this example, set Output type to **DOUBLE**.

```
'not a number'
```

Every row: NULL

### An invalid conversion raises an error

```
CAST('unknown' AS DOUBLE)
```

This input is rejected: Could not convert string 'unknown' to DOUBLE

## Related functions

[TRY\_CAST

Convert a value to another data type, returning a missing value if conversion fails.

](https://oplema.com/docs/strata/functions/try-cast)[typeof

Return the name of an expression's data type.

](https://oplema.com/docs/strata/functions/typeof)[constant\_or\_null

Return the first argument, or a missing value if the second argument is missing.

](https://oplema.com/docs/strata/functions/constant-or-null)[coalesce

Replace missing values with the first available alternative.

](https://oplema.com/docs/strata/functions/coalesce)

[Browse conversion & identifiers](https://oplema.com/docs/strata/functions#conversion-&-identifiers) [DuckDB documentation](https://duckdb.org/docs/current/sql/expressions/cast.html)

Function metadata from DuckDB, used under the [MIT license](https://github.com/duckdb/duckdb/blob/v1.5.4/LICENSE).
