---
title: "enum_code function in Strata | Oplema"
description: "Get the numeric value that backs an enum value, so you can sort or compare by position. Write it as enum_code(enum) in a Strata Formula or Filter."
url: "https://oplema.com/docs/strata/functions/enum-code"
updated: "2026-11-04"
---

# enum\_code

Returns the numeric value backing the given enum value.

## Try an expression

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

### Expression

```
enum_code('happy'::ENUM('sad', 'ok', 'happy', 'anxious'))
```

### Result

```
2
```

The expression returns `UTINYINT`. Formula stores it as `BIGINT` in this example. To use your own data, replace the example values with column names. Keep format strings and other options as written.

Try it live in Formula

Result
| id | result |
| --- | --- |
| 1 | 2 |

## Arguments and types

```
enum_code(enum)
```

**enum**

Any value

Supported signatures (1)

```
enum_code(enum: ANY) → ANY
```

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

## Things to know

If the first argument is missing, the result is NULL.

## Related functions

[enum\_range\_boundary

Returns the range between the two given enum values as an array. The values must be of the same enum type. When the first parameter is NULL, the result starts with the first value of the enum type. When the second parameter is NULL, the result ends with the last value of the enum type.

](https://oplema.com/docs/strata/functions/enum-range-boundary)[enum\_first

Returns the first value of the input enum type.

](https://oplema.com/docs/strata/functions/enum-first)[enum\_last

Returns the last value of the input enum type.

](https://oplema.com/docs/strata/functions/enum-last)[enum\_range

Returns all values of the input enum type as an array.

](https://oplema.com/docs/strata/functions/enum-range)

[Browse enums](https://oplema.com/docs/strata/functions#enums) [DuckDB documentation](https://duckdb.org/docs/current/sql/functions/enum.html#enum_codeenum_value)

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