Functions for working with strings

**Syntax**

```
trimBoth(s[, trim_characters])
```

**Aliases**: `trim`

**Arguments**

- `s` — String to trim. [`String`](/docs/sql-reference/data-types/string)
- `trim_characters` — Optional. Characters to trim. If not specified, common whitespace characters are removed. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns the string with specified characters trimmed from both ends. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT trimBoth('$$ClickHouse$$', '$')
```

```
┌─trimBoth('$$⋯se$$', '$')─┐
│ ClickHouse               │
└──────────────────────────┘
```

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

Introduced in: v20.1.0

Removes the specified characters from the start of a string.
By default, removes common whitespace (ASCII) characters.

**Syntax**

```
trimLeft(input[, trim_characters])
```

**Aliases**: `ltrim`

**Arguments**

- `input` — String to trim. [`String`](/docs/sql-reference/data-types/string)
- `trim_characters` — Optional. Characters to trim. If not specified, common whitespace characters are removed. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns the string with specified characters trimmed from the left. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT trimLeft('ClickHouse', 'Click');
```

```
┌─trimLeft('Cl⋯', 'Click')─┐
│ House                    │
└──────────────────────────┘
```

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

Introduced in: v20.1.0

Removes the specified characters from the end of a string.
By default, removes common whitespace (ASCII) characters.

**Syntax**

```
trimRight(s[, trim_characters])
```

**Aliases**: `rtrim`

**Arguments**

- `s` — String to trim. [`String`](/docs/sql-reference/data-types/string)
- `trim_characters` — Optional characters to trim. If not specified, common whitespace characters are removed. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns the string with specified characters trimmed from the right. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT trimRight('ClickHouse','House');
```

```
┌─trimRight('C⋯', 'House')─┐
│ Click                    │
└──────────────────────────┘
```

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

Introduced in: v25.6.0

Accepts a string and decodes it using [Base32](https://datatracker.ietf.org/doc/html/rfc4648#section-6) encoding scheme.

**Syntax**

```
tryBase32Decode(encoded)
```

**Arguments**

- `encoded` — String column or constant to decode. If the string is not valid Base32-encoded, returns an empty string in case of error. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns a string containing the decoded value of the argument. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT tryBase32Decode('IVXGG33EMVSA====');
```

```
┌─tryBase32Decode('IVXGG33EMVSA====')─┐
│ Encoded                             │
└─────────────────────────────────────┘
```

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

Introduced in: v22.10.0

Like [`base58Decode`](#base58Decode), but returns an empty string in case of error.

**Syntax**

```
tryBase58Decode(encoded[, expected_size])
```

**Arguments**

- `encoded` — String column or constant. If the string is not valid Base58-encoded, returns an empty string in case of error. [`String`](/docs/sql-reference/data-types/string)
- `expected_size` — Optional. Expected decoded size in bytes. When 32 or 64, an optimized decoder is used; for other values, the generic decoder is used. [`UInt8, UInt16, UInt32, or UInt64`](/docs/sql-reference/data-types/int-uint)

**Returned value**

Returns a string containing the decoded value of the argument. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT tryBase58Decode('3dc8KtHrwM') AS res, tryBase58Decode('invalid') AS res_invalid;
```

```
┌─res─────┬─res_invalid─┐
│ Encoded │             │
└─────────┴─────────────┘
```

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

Introduced in: v18.16.0

Like [`base64Decode`](#base64Decode), but returns an empty string in case of error.

**Syntax**

```
tryBase64Decode(encoded)
```

**Arguments**

- `encoded` — String column or constant to decode. If the string is not valid Base64-encoded, returns an empty string in case of error. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns a string containing the decoded value of the argument. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT tryBase64Decode('Y2xpY2tob3VzZQ==')
```

```
┌─tryBase64Decode('Y2xpY2tob3VzZQ==')─┐
│ clickhouse                          │
└─────────────────────────────────────┘
```

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

Introduced in: v18.16.0

Like [`base64URLDecode`](#base64URLDecode), but returns an empty string in case of error.

**Syntax**

```
tryBase64URLDecode(encoded)
```

**Arguments**

- `encoded` — String column or constant to decode. If the string is not valid Base64-encoded, returns an empty string in case of error. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns a string containing the decoded value of the argument. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT tryBase64URLDecode('aHR0cHM6Ly9jbGlja2hvdXNlLmNvbQ')
```

```
┌─tryBase64URLDecode('aHR0cHM6Ly9jbGlja2hvdXNlLmNvbQ')─┐
│ https://clickhouse.com                               │
└──────────────────────────────────────────────────────┘
```

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

Introduced in: v24.1.0

Returns the Unicode (UTF-8) representation (ToUnicode algorithm) of a domain name according to the [Internationalized Domain Names in Applications](https://en.wikipedia.org/wiki/Internationalized_domain_name#Internationalizing_Domain_Names_in_Applications) (IDNA) mechanism.
In case of an error it returns an empty string instead of throwing an exception.

**Syntax**

```
tryIdnaEncode(s)
```

**Arguments**

- `s` — Input string. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns an ASCII representation of the input string according to the IDNA mechanism of the input value, or empty string if input is invalid. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT tryIdnaEncode('straße.münchen.de')
```

```
┌─tryIdnaEncode('straße.münchen.de')──┐
│ xn--strae-oqa.xn--mnchen-3ya.de     │
└─────────────────────────────────────┘
```

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

Introduced in: v24.1.0

Like `punycodeDecode` but returns an empty string if no valid Punycode-encoded string is given.

**Syntax**

```
tryPunycodeDecode(s)
```

**Arguments**

- `s` — Punycode-encoded string. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns the plaintext of the input value, or empty string if input is invalid. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT tryPunycodeDecode('Mnchen-3ya')
```

```
┌─tryPunycodeDecode('Mnchen-3ya')─┐
│ München                         │
└─────────────────────────────────┘
```

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

Introduced in: v1.1.0

Converts the ASCII Latin symbols in a string to uppercase.

**Syntax**

```
upper(s)
```

**Aliases**: `ucase`

**Arguments**

- `s` — The string to convert to uppercase. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns an uppercase string from `s`. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT upper('clickhouse')
```

```
┌─upper('clickhouse')─┐
│ CLICKHOUSE          │
└─────────────────────┘
```

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

Introduced in: v1.1.0