# ULID (/docs/reference/sql/functions/ulid)



This page describes the RawTree engine binary used to generate this reference. It does not define Query API support. Descriptions retain upstream ClickHouse terminology. See [SQL interface scope](/docs/reference/clickhouse-compatibility#service-interfaces).

ULIDStringToDateTime [#ulidstringtodatetime]

This function extracts the timestamp from a [ULID](https://github.com/ulid/spec).

**Syntax**

```sql
ULIDStringToDateTime(ulid[, timezone])
```

**Arguments**

* `ulid` — Input ULID. [`String`](/reference/data-types/string) or [`FixedString(26)`](/reference/data-types/fixedstring)
* `timezone` — Optional. Timezone name for the returned value. [`String`](/reference/data-types/string)

**Returned value**

Timestamp with milliseconds precision. [`DateTime64(3)`](/reference/data-types/datetime64)

**Examples**

**Usage example**

```sql title=Query
SELECT ULIDStringToDateTime('01GNB2S2FGN2P93QPXDNB4EN2R')
```

```text title=Response
┌─ULIDStringToDateTime('01GNB2S2FGN2P93QPXDNB4EN2R')─┐
│                            2022-12-28 00:40:37.616 │
└────────────────────────────────────────────────────┘
```

*Introduced in version 23.3.0.*

generateULID [#generateulid]

Generates a [Universally Unique Lexicographically Sortable Identifier (ULID)](https://github.com/ulid/spec).

**Syntax**

```sql
generateULID([x])
```

**Arguments**

* `x` — Optional. An expression resulting in any of the supported data types. The resulting value is discarded, but the expression itself if used for bypassing [common subexpression elimination](/reference/functions/regular-functions/overview#common-subexpression-elimination) if the function is called multiple times in one query. [`Any`](/reference/data-types)

**Returned value**

Returns a ULID. [`FixedString(26)`](/reference/data-types/fixedstring)

**Examples**

**Usage example**

```sql title=Query
SELECT generateULID()
```

```text title=Response
┌─generateULID()─────────────┐
│ 01GNB2S2FGN2P93QPXDNB4EN2R │
└────────────────────────────┘
```

**Usage example if it is needed to generate multiple values in one row**

```sql title=Query
SELECT generateULID(1), generateULID(2)
```

```text title=Response
┌─generateULID(1)────────────┬─generateULID(2)────────────┐
│ 01GNB2SGG4RHKVNT9ZGA4FFMNP │ 01GNB2SGG4V0HMQVH4VBVPSSRB │
└────────────────────────────┴────────────────────────────┘
```

*Introduced in version 23.2.0.*
