Type conversion functions

Supported arguments:

- String representations of UUID in standard format (8-4-4-4-12 hexadecimal digits).
- String representations of UUID without hyphens (32 hexadecimal digits).

Unsupported arguments (return zero UUID):

- Invalid string formats.
- Non-string types.

**Syntax**

```
toUUIDOrZero(x)
```

**Arguments**

- `x` — A string representation of a UUID. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns a UUID value if successful, otherwise zero UUID (`00000000-0000-0000-0000-000000000000`). [`UUID`](/docs/sql-reference/data-types/uuid)

**Examples**

**Usage example**

```
SELECT
    toUUIDOrZero('550e8400-e29b-41d4-a716-446655440000') AS valid_uuid,
    toUUIDOrZero('invalid-uuid') AS invalid_uuid
```

```
┌─valid_uuid───────────────────────────┬─invalid_uuid─────────────────────────┐
│ 550e8400-e29b-41d4-a716-446655440000 │ 00000000-0000-0000-0000-000000000000 │
└──────────────────────────────────────┴──────────────────────────────────────┘
```

## toUnixTimestamp64Micro[​](#toUnixTimestamp64Micro "Direct link to toUnixTimestamp64Micro")

Introduced in: v20.5.0

Converts a [`DateTime64`](/docs/sql-reference/data-types/datetime64) to a [`Int64`](/docs/sql-reference/data-types/int-uint) value with fixed microsecond precision.
The input value is scaled up or down appropriately depending on its precision.

Note

The output value is relative to UTC, not to the timezone of the input value.

**Syntax**

```
toUnixTimestamp64Micro(value)
```

**Arguments**

- `value` — DateTime64 value with any precision. [`DateTime64`](/docs/sql-reference/data-types/datetime64)

**Returned value**

Returns a Unix timestamp in microseconds. [`Int64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
WITH toDateTime64('2025-02-13 23:31:31.011123', 6, 'UTC') AS dt64
SELECT toUnixTimestamp64Micro(dt64);
```

```
┌─toUnixTimestamp64Micro(dt64)─┐
│               1739489491011123 │
└────────────────────────────────┘
```

## toUnixTimestamp64Milli[​](#toUnixTimestamp64Milli "Direct link to toUnixTimestamp64Milli")

Introduced in: v20.5.0

Converts a [`DateTime64`](/docs/sql-reference/data-types/datetime64) to a [`Int64`](/docs/sql-reference/data-types/int-uint) value with fixed millisecond precision.
The input value is scaled up or down appropriately depending on its precision.

Note

The output value is relative to UTC, not to the timezone of the input value.

**Syntax**

```
toUnixTimestamp64Milli(value)
```

**Arguments**

- `value` — DateTime64 value with any precision. [`DateTime64`](/docs/sql-reference/data-types/datetime64)

**Returned value**

Returns a Unix timestamp in milliseconds. [`Int64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
WITH toDateTime64('2025-02-13 23:31:31.011', 3, 'UTC') AS dt64
SELECT toUnixTimestamp64Milli(dt64);
```

```
┌─toUnixTimestamp64Milli(dt64)─┐
│                1739489491011 │
└──────────────────────────────┘
```

## toUnixTimestamp64Nano[​](#toUnixTimestamp64Nano "Direct link to toUnixTimestamp64Nano")

Introduced in: v20.5.0

Converts a [`DateTime64`](/docs/sql-reference/data-types/datetime64) to a [`Int64`](/docs/sql-reference/functions/type-conversion-functions#toInt64) value with fixed nanosecond precision.
The input value is scaled up or down appropriately depending on its precision.

Note

The output value is relative to UTC, not to the timezone of the input value.

**Syntax**

```
toUnixTimestamp64Nano(value)
```

**Arguments**

- `value` — DateTime64 value with any precision. [`DateTime64`](/docs/sql-reference/data-types/datetime64)

**Returned value**

Returns a Unix timestamp in nanoseconds. [`Int64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
WITH toDateTime64('2025-02-13 23:31:31.011123456', 9, 'UTC') AS dt64
SELECT toUnixTimestamp64Nano(dt64);
```

```
┌─toUnixTimestamp64Nano(dt64)────┐
│            1739489491011123456 │
└────────────────────────────────┘
```

## toUnixTimestamp64Second[​](#toUnixTimestamp64Second "Direct link to toUnixTimestamp64Second")

Introduced in: v24.12.0

Converts a [`DateTime64`](/docs/sql-reference/data-types/datetime64) to a [`Int64`](/docs/sql-reference/data-types/int-uint) value with fixed second precision.
The input value is scaled up or down appropriately depending on its precision.

Note

The output value is relative to UTC, not to the timezone of the input value.

**Syntax**

```
toUnixTimestamp64Second(value)
```

**Arguments**

- `value` — DateTime64 value with any precision. [`DateTime64`](/docs/sql-reference/data-types/datetime64)

**Returned value**

Returns a Unix timestamp in seconds. [`Int64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
WITH toDateTime64('2025-02-13 23:31:31.011', 3, 'UTC') AS dt64
SELECT toUnixTimestamp64Second(dt64);
```

```
┌─toUnixTimestamp64Second(dt64)─┐
│                    1739489491 │
└───────────────────────────────┘
```