Functions for working with URLs

**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)
```

**Arguments**

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

**Returned value**

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

**Examples**

**Usage example**

```
SELECT cutQueryString('http://example.com/path?query=value&param=123#fragment');
```

```
┌─cutQueryString('http://example.com/path?query=value&param=123#fragment')─┐
│ http://example.com/path#fragment                                         │
└──────────────────────────────────────────────────────────────────────────┘
```

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

Introduced in: v1.1.0

Removes the query string and fragment identifier, including the question mark and number sign, from a URL.

**Syntax**

```
cutQueryStringAndFragment(url)
```

**Arguments**

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

**Returned value**

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

**Examples**

**Usage example**

```
SELECT cutQueryStringAndFragment('http://example.com/path?query=value&param=123#fragment');
```

```
┌─cutQueryStringAndFragment('http://example.com/path?query=value&param=123#fragment')─┐
│ http://example.com/path                                                             │
└─────────────────────────────────────────────────────────────────────────────────────┘
```

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

Introduced in: v1.1.0

Returns the part of the domain that includes top-level subdomains up to the [first significant subdomain](/docs/sql-reference/functions/url-functions#firstSignificantSubdomain).

**Syntax**

```
cutToFirstSignificantSubdomain(url)
```

**Arguments**

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

**Returned value**

Returns the part of the domain that includes top-level subdomains up to the first significant subdomain if possible, otherwise returns an empty string. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT
    cutToFirstSignificantSubdomain('https://news.clickhouse.com.tr/'),
    cutToFirstSignificantSubdomain('www.tr'),
    cutToFirstSignificantSubdomain('tr');
```

```
┌─cutToFirstSignificantSubdomain('https://news.clickhouse.com.tr/')─┬─cutToFirstSignificantSubdomain('www.tr')─┬─cutToFirstSignificantSubdomain('tr')─┐
│ clickhouse.com.tr                                                 │ tr                                       │                                      │
└───────────────────────────────────────────────────────────────────┴──────────────────────────────────────────┴──────────────────────────────────────┘
```

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

Introduced in: v21.1.0

Returns the part of the domain that includes top-level subdomains up to the first significant subdomain. Accepts custom [TLD list](https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains) name. This function can be useful if you need a fresh TLD list or if you have a custom list.

**Configuration example**

```
<!-- <top_level_domains_path>/var/lib/clickhouse/top_level_domains/</top_level_domains_path> -->
<top_level_domains_lists>
    <!-- https://publicsuffix.org/list/public_suffix_list.dat -->
    <public_suffix_list>public_suffix_list.dat</public_suffix_list>
    <!-- NOTE: path is under top_level_domains_path -->
</top_level_domains_lists>
```

**Syntax**

```
cutToFirstSignificantSubdomainCustom(url, tld_list_name)
```

**Arguments**

- `url` — URL or domain string to process. [`String`](/docs/sql-reference/data-types/string)
- `tld_list_name` — Name of the custom TLD list configured in ClickHouse. [`const String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns the part of the domain that includes top-level subdomains up to the first significant subdomain. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Using custom TLD list for non-standard domains**

```
SELECT cutToFirstSignificantSubdomainCustom('bar.foo.there-is-no-such-domain', 'public_suffix_list')
```

```
foo.there-is-no-such-domain
```

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

Introduced in: v22.10.0

Returns the part of the domain that includes top-level subdomains up to the first significant subdomain.
Accepts custom [TLD list](https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains) name.
This function can be useful if you need a fresh TLD list or if you have a custom list.
Similar to [cutToFirstSignificantSubdomainCustom](#cutToFirstSignificantSubdomainCustom) but conforms to RFC 3986.

**Configuration example**

```
<!-- <top_level_domains_path>/var/lib/clickhouse/top_level_domains/</top_level_domains_path> -->
<top_level_domains_lists>
    <!-- https://publicsuffix.org/list/public_suffix_list.dat -->
    <public_suffix_list>public_suffix_list.dat</public_suffix_list>
    <!-- NOTE: path is under top_level_domains_path -->
</top_level_domains_lists>
```

**Syntax**

```
cutToFirstSignificantSubdomainCustomRFC(url, tld_list_name)
```

**Arguments**

- `url` — URL or domain string to process according to RFC 3986. - `tld_list_name` — Name of the custom TLD list configured in ClickHouse.

**Returned value**

Returns the part of the domain that includes top-level subdomains up to the first significant subdomain. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT cutToFirstSignificantSubdomainCustomRFC('www.foo', 'public_suffix_list');
```

```
┌─cutToFirstSignificantSubdomainCustomRFC('www.foo', 'public_suffix_list')─────┐
│ www.foo                                                                      │
└──────────────────────────────────────────────────────────────────────────────┘
```

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

Introduced in: v21.1.0

Returns the part of the domain that includes top-level subdomains up to the first significant subdomain without stripping 'www'. Accepts custom TLD list name. It can be useful if you need a fresh TLD list or if you have a custom list.

**Configuration example**

```
<!-- <top_level_domains_path>/var/lib/clickhouse/top_level_domains/</top_level_domains_path> -->
<top_level_domains_lists>
    <!-- https://publicsuffix.org/list/public_suffix_list.dat -->
    <public_suffix_list>public_suffix_list.dat</public_suffix_list>
    <!-- NOTE: path is under top_level_domains_path -->
</top_level_domains_lists>
    

**Syntax**

```sql
cutToFirstSignificantSubdomainCustomWithWWW(url, tld_list_name)
```

**Arguments**

- `url` — URL or domain string to process. - `tld_list_name` — Name of the custom TLD list configured in ClickHouse.

**Returned value**

Part of the domain that includes top-level subdomains up to the first significant subdomain without stripping 'www'. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**