Functions for working with URLs

[Edit this page](https://github.com/ClickHouse/ClickHouse/tree/master/docs/en/sql-reference/functions/url-functions.md)

## Overview[​](#overview "Direct link to Overview")

Note

The functions mentioned in this section are optimized for maximum performance and for the most part do not follow the RFC-3986 standard.
Functions which implement RFC-3986 have `RFC` appended to their function name and are generally slower.

You can generally use the non-`RFC` function variants when working with publicly registered domains that contain neither user strings nor `@` symbols.
The table below details which symbols in a URL can (`✔`) or cannot (`✗`) be parsed by the respective `RFC` and non-`RFC` variants:

|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Symbol non-`RFC` `RFC`|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | ' ' ✗ ✗|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | \t ✗ ✗|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | < ✗ ✗|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | > ✗ ✗|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | % ✗ ✔\*|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | { ✗ ✗|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | } ✗ ✗|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | | ✗ ✗|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | \\ ✗ ✗|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | ^ ✗ ✗|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | ~ ✗ ✔\*|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | [ ✗ ✗|  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | ] ✗ ✔|  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | | ; ✗ ✔\*|  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | | = ✗ ✔\*|  |  |  | | --- | --- | --- | | & ✗ ✔\* | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |

symbols marked `*` are sub-delimiters in RFC 3986 and allowed for user info following the `@` symbol.

There are two types of URL functions:

- Functions that extract parts of a URL. If the relevant part isn't present in a URL, an empty string is returned.
- Functions that remove part of a URL. If the URL does not have anything similar, the URL remains unchanged.

Note

The functions below are generated from the `system.functions` system table.

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

Introduced in: v1.1.0

Returns an array containing the URL, truncated at the end by the symbols `/`, `?` and `#` in the path and query string. Consecutive separator characters are counted as one. The result includes the protocol and host as the first element, with progressively longer paths forming a hierarchy.

**Syntax**

```
URLHierarchy(url)
```

**Arguments**

- `url` — The URL to process. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns an array of progressively longer URLs forming a hierarchy. [`Array(String)`](/docs/sql-reference/data-types/array)

**Examples**

**Basic usage**

```
SELECT URLHierarchy('https://example.com/a/b?c=1')
```

```
['https://example.com/','https://example.com/a/','https://example.com/a/b','https://example.com/a/b?c=1']
```

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

Introduced in: v1.1.0

Returns an array containing the path component of the URL, truncated at the end by the symbols `/`, `?` and `#`. Unlike `URLHierarchy`, the result does not include the protocol and host — it starts from the path. Consecutive separator characters are counted as one.

**Syntax**

```
URLPathHierarchy(url)
```

**Arguments**

- `url` — The URL to process. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns an array of progressively longer URL path components forming a hierarchy. [`Array(String)`](/docs/sql-reference/data-types/array)

**Examples**

**Basic usage**

```
SELECT URLPathHierarchy('https://example.com/a/b?c=1')
```

```
['/a/','/a/b','/a/b?c=1']
```

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

Introduced in: v1.1.0

Removes the fragment identifier, including the number sign, from a URL.

**Syntax**

```
cutFragment(url)
```

**Arguments**

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

**Returned value**

Returns the URL with fragment identifier removed. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT cutFragment('http://example.com/path?query=value#fragment123');
```

```
┌─cutFragment('http://example.com/path?query=value#fragment123')─┐
│ http://example.com/path?query=value                            │
└────────────────────────────────────────────────────────────────┘
```

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

Introduced in: v1.1.0

Removes the query string, including the question mark from a URL.

**Syntax**

```
cutQueryString(url)
```