Other functions

If `L` is outside the range `[0...1]`, `C` is negative, or `H` is outside the range `[0...360]`, the result is implementation-defined.

Note

**OKLCH** is a cylindrical version of the OKLab colour space.
It's three coordinates are `L` (the lightness in the range `[0...1]`), `C` (chroma `>= 0`) and `H` (hue in degrees from `[0...360]`).
OKLab/OKLCH is designed to be perceptually uniform while remaining cheap to compute.

The conversion is the inverse of [`colorSRGBToOKLCH`](#colorSRGBToOKLCH):

1. OKLCH to OKLab.
2. OKLab to Linear sRGB
3. Linear sRGB to sRGB

The second argument gamma is used at the last stage.

For references of colors in OKLCH space, and how they correspond to sRGB colors please see <https://oklch.com/>.

**Syntax**

```
colorOKLCHToSRGB(tuple [, gamma])
```

**Arguments**

- `tuple` — A tuple of three numeric values `L`, `C`, `H`, where `L` is in the range `[0...1]`, `C >= 0` and `H` is in the range `[0...360]`. [`Tuple(Float64, Float64, Float64)`](/docs/sql-reference/data-types/tuple)
- `gamma` — Optional. The exponent that is used to transform linear sRGB back to sRGB by applying `(x ^ (1 / gamma)) * 255` for each channel `x`. Defaults to `2.2`. [`Float64`](/docs/sql-reference/data-types/float)

**Returned value**

Returns a tuple (R, G, B) representing sRGB color values. [`Tuple(Float64, Float64, Float64)`](/docs/sql-reference/data-types/tuple)

**Examples**

**Convert OKLCH to sRGB**

```
SELECT colorOKLCHToSRGB((0.6, 0.12, 40)) AS rgb;
```

```
┌─rgb───────────────────────────────────────────────────────┐
│ (186.02058688365264,100.68677189684993,71.67819977081575) │
└───────────────────────────────────────────────────────────┘
```

**Convert OKLCH to sRGB (UInt8)**

```
WITH colorOKLCHToSRGB((0.6, 0.12, 40)) AS t
SELECT tuple(toUInt8(t.1), toUInt8(t.2), toUInt8(t.3)) AS RGB;
```

```
┌─RGB──────────┐
│ (186,100,71) │
└──────────────┘
```

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

Introduced in: v26.2.0

Converts a colour encoded in the **sRGB** colour space to the perceptually uniform **OKLAB** colour space.

If any input channel is outside `[0...255]` or the gamma value is non-positive, the behaviour is implementation-defined.

Note

**OKLAB** is a perceptually uniform color space.
Its three coordinates are `L` (the lightness in the range `[0...1]`), `a (Green-Red axis)` and `b (Blue-Yellow axis)`.
OKLab is designed to be perceptually uniform while remaining cheap to compute.

The conversion consists of two stages:

1. sRGB to Linear sRGB
2. Linear sRGB to OKLab

**Syntax**

```
colorSRGBToOKLAB(tuple[, gamma])
```

**Arguments**

- `tuple` — Tuple of three values R, G, B in the range `[0...255]`. [`Tuple(UInt8, UInt8, UInt8)`](/docs/sql-reference/data-types/tuple)
- `gamma` — Optional. Exponent that is used to linearize sRGB by applying `(x / 255)^gamma` to each channel `x`. Defaults to `2.2`. [`Float64`](/docs/sql-reference/data-types/float)

**Returned value**

Returns a tuple (L, a, b) representing the OKLAB color space values. [`Tuple(Float64, Float64, Float64)`](/docs/sql-reference/data-types/tuple)

**Examples**

**Convert sRGB to OKLAB**

```
SELECT colorSRGBToOKLAB((128, 64, 32), 2.2) AS lab;
```

```
┌─lab──────────────────────────────────────────────────────────┐
│ (0.4436238384931984,0.07266246769242975,0.07500108778529994) │
└──────────────────────────────────────────────────────────────┘
```

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

Introduced in: v25.7.0

Converts a colour encoded in the **sRGB** colour space to the perceptually uniform **OKLCH** colour space.

If any input channel is outside `[0...255]` or the gamma value is non-positive, the behaviour is implementation-defined.

Note

**OKLCH** is a cylindrical version of the OKLab colour space.
It's three coordinates are `L` (the lightness in the range `[0...1]`), `C` (chroma `>= 0`) and `H` (the hue in degrees from `[0...360]`).
OKLab/OKLCH is designed to be perceptually uniform while remaining cheap to compute.

The conversion consists of three stages:

1. sRGB to Linear sRGB
2. Linear sRGB to OKLab
3. OKLab to OKLCH.

For references of colors in the OKLCH space, and how they correspond to sRGB colors, please see <https://OKLCH.com/>.

**Syntax**

```
colorSRGBToOKLCH(tuple[, gamma])
```

**Arguments**

- `tuple` — Tuple of three values R, G, B in the range `[0...255]`. [`Tuple(UInt8, UInt8, UInt8)`](/docs/sql-reference/data-types/tuple)
- `gamma` — Optional. Exponent that is used to linearize sRGB by applying `(x / 255)^gamma` to each channel `x`. Defaults to `2.2`. [`Float64`](/docs/sql-reference/data-types/float)

**Returned value**

Returns a tuple (L, C, H) representing the OKLCH color space values. [`Tuple(Float64, Float64, Float64)`](/docs/sql-reference/data-types/tuple)

**Examples**

**Convert sRGB to OKLCH**

```
SELECT colorSRGBToOKLCH((128, 64, 32), 2.2) AS lch;
```

```
┌─lch───────────────────────────────────────────────────────┐
│ (0.4436238384931984,0.1044269954567863,45.90734548193018) │
└───────────────────────────────────────────────────────────┘
```

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

Introduced in: v21.3.0

Returns the connection ID of the client that submitted the current query.
This function is most useful in debugging scenarios.
It was created for compatibility with MySQL's `CONNECTION_ID` function.
It is not typically used in production queries.

**Syntax**

```
connectionId()
```

**Arguments**

- None.

**Returned value**

Returns the connection ID of the current client. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT connectionId();
```

```
┌─connectionId()─┐
│              0 │
└────────────────┘
```

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

Introduced in: v20.8.0

Returns the number of decimal digits needed to represent a value.

Note

This function takes into account the scales of decimal values i.e., it calculates the result over the underlying integer type which is `(value * scale)`.

For example:

- `countDigits(42) = 2`
- `countDigits(42.000) = 5`
- `countDigits(0.04200) = 4`

Tip

You can check decimal overflow for `Decimal64` with `countDigits(x) > 18`,
although it is slower than [`isDecimalOverflow`](#isDecimalOverflow).

**Syntax**

```
countDigits(x)
```

**Arguments**

- `x` — An integer or decimal value. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Decimal`](/docs/sql-reference/data-types/decimal)

**Returned value**

Returns the number of digits needed to represent `x`. [`UInt8`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT countDigits(toDecimal32(1, 9)), countDigits(toDecimal32(-1, 9)),
       countDigits(toDecimal64(1, 18)), countDigits(toDecimal64(-1, 18)),
       countDigits(toDecimal128(1, 38)), countDigits(toDecimal128(-1, 38));
```

```
┌─countDigits(toDecimal32(1, 9))─┬─countDigits(toDecimal32(-1, 9))─┬─countDigits(toDecimal64(1, 18))─┬─countDigits(toDecimal64(-1, 18))─┬─countDigits(toDecimal128(1, 38))─┬─countDigits(toDecimal128(-1, 38))─┐
│                             10 │                              10 │                              19 │                               19 │                               39 │                                39 │
└────────────────────────────────┴─────────────────────────────────┴─────────────────────────────────┴──────────────────────────────────┴──────────────────────────────────┴───────────────────────────────────┘
```

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

Introduced in: v1.1.0

Returns the name of the current database.
Useful in table engine parameters of `CREATE TABLE` queries where you need to specify the database.

Also see the [`SET` statement](/docs/sql-reference/statements/use).

**Syntax**

```
currentDatabase()
```

**Aliases**: `current_database`, `SCHEMA`, `DATABASE`

**Arguments**

- None.

**Returned value**

Returns the current database name. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT currentDatabase()
```