# URL (/docs/reference/sql/functions/url)



This page describes the RawTree engine binary used to generate this reference. It does not define Query API support. Descriptions retain upstream ClickHouse terminology. See [SQL interface scope](/docs/reference/clickhouse-compatibility#service-interfaces).

URLHierarchy [#urlhierarchy]

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

```sql
URLHierarchy(url)
```

**Arguments**

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

**Returned value**

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

**Examples**

**Basic usage**

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

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

*Introduced in version 1.1.0.*

URLPathHierarchy [#urlpathhierarchy]

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

```sql
URLPathHierarchy(url)
```

**Arguments**

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

**Returned value**

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

**Examples**

**Basic usage**

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

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

*Introduced in version 1.1.0.*

cutFragment [#cutfragment]

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

**Syntax**

```sql
cutFragment(url)
```

**Arguments**

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

**Returned value**

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

**Examples**

**Usage example**

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

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

*Introduced in version 1.1.0.*

cutQueryString [#cutquerystring]

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

**Syntax**

```sql
cutQueryString(url)
```

**Arguments**

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

**Returned value**

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

**Examples**

**Usage example**

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

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

*Introduced in version 1.1.0.*

cutQueryStringAndFragment [#cutquerystringandfragment]

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

**Syntax**

```sql
cutQueryStringAndFragment(url)
```

**Arguments**

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

**Returned value**

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

**Examples**

**Usage example**

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

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

*Introduced in version 1.1.0.*

cutToFirstSignificantSubdomain [#cuttofirstsignificantsubdomain]

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

**Syntax**

```sql
cutToFirstSignificantSubdomain(url)
```

**Arguments**

* `url` — URL or domain string to process. [`String`](/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`](/reference/data-types/string)

**Examples**

**Usage example**

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

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

*Introduced in version 1.1.0.*

cutToFirstSignificantSubdomainCustom [#cuttofirstsignificantsubdomaincustom]

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

```yaml

<top_level_domains_lists>
    
    <public_suffix_list>public_suffix_list.dat</public_suffix_list>
    
</top_level_domains_lists>
```

**Syntax**

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

**Arguments**

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

**Returned value**

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

**Examples**

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

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

```text title=Response
foo.there-is-no-such-domain
```

*Introduced in version 21.1.0.*

cutToFirstSignificantSubdomainCustomRFC [#cuttofirstsignificantsubdomaincustomrfc]

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

```xml

<top_level_domains_lists>
    
    <public_suffix_list>public_suffix_list.dat</public_suffix_list>
    
</top_level_domains_lists>
```

**Syntax**

```sql
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 RawTree.

**Returned value**

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

**Examples**

**Usage example**

```sql title=Query
SELECT cutToFirstSignificantSubdomainCustomRFC('www.foo', 'public_suffix_list');
```

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

*Introduced in version 22.10.0.*

cutToFirstSignificantSubdomainCustomWithWWW [#cuttofirstsignificantsubdomaincustomwithwww]

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

````yaml

<top_level_domains_lists>
    
    <public_suffix_list>public_suffix_list.dat</public_suffix_list>
    
</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 RawTree.

**Returned value**

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

**Examples**

**Usage example**

```sql title=Query
SELECT cutToFirstSignificantSubdomainCustomWithWWW('www.foo', 'public_suffix_list');
```

```text title=Response
┌─cutToFirstSignificantSubdomainCustomWithWWW('www.foo', 'public_suffix_list')─┐
│ www.foo                                                                      │
└──────────────────────────────────────────────────────────────────────────────┘
```

*Introduced in version 21.1.0.*

cutToFirstSignificantSubdomainCustomWithWWWRFC [#cuttofirstsignificantsubdomaincustomwithwwwrfc]

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.
Similar to [cutToFirstSignificantSubdomainCustomWithWWW](#cutToFirstSignificantSubdomainCustomWithWWW) but conforms to [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986).

**Configuration example**

````xml

<top_level_domains_lists>
    
    <public_suffix_list>public_suffix_list.dat</public_suffix_list>
    
</top_level_domains_lists>

**Syntax**

```sql
cutToFirstSignificantSubdomainCustomWithWWWRFC(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 RawTree.

**Returned value**

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

**Examples**

**RFC 3986 parsing preserving www with custom TLD list**

```sql title=Query
SELECT cutToFirstSignificantSubdomainCustomWithWWWRFC('https://www.subdomain.example.custom', 'public_suffix_list')
```

```text title=Response
www.example.custom
```

*Introduced in version 22.10.0.*

cutToFirstSignificantSubdomainRFC [#cuttofirstsignificantsubdomainrfc]

Returns the part of the domain that includes top-level subdomains up to the ["first significant subdomain"](/reference/functions/regular-functions/url-functions#firstSignificantSubdomain). Similar to [`cutToFirstSignificantSubdomain`](#cutToFirstSignificantSubdomain) but conforms to [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986).

**Syntax**

```sql
cutToFirstSignificantSubdomainRFC(url)
```

**Arguments**

* `url` — URL or domain string to process according to RFC 3986. [`String`](/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`](/reference/data-types/string)

**Examples**

**Usage example**

```sql title=Query
SELECT
    cutToFirstSignificantSubdomain('http://user:password@example.com:8080'),
    cutToFirstSignificantSubdomainRFC('http://user:password@example.com:8080');
```

```text title=Response
┌─cutToFirstSignificantSubdomain('http://user:password@example.com:8080')─┬─cutToFirstSignificantSubdomainRFC('http://user:password@example.com:8080')─┐
│                                                                         │ example.com                                                                │
└─────────────────────────────────────────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────┘
```

*Introduced in version 22.10.0.*

cutToFirstSignificantSubdomainWithWWW [#cuttofirstsignificantsubdomainwithwww]

Returns the part of the domain that includes top-level subdomains up to the "first significant subdomain", without stripping '[www](http://www).'.

Similar to [`cutToFirstSignificantSubdomain`](#cutToFirstSignificantSubdomain) but preserves the '[www](http://www).' prefix if present.

**Syntax**

```sql
cutToFirstSignificantSubdomainWithWWW(url)
```

**Arguments**

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

**Returned value**

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

**Examples**

**Usage example**

```sql title=Query
SELECT
    cutToFirstSignificantSubdomainWithWWW('https://news.clickhouse.com.tr/'),
    cutToFirstSignificantSubdomainWithWWW('www.tr'),
    cutToFirstSignificantSubdomainWithWWW('tr');
```

```text title=Response
┌─cutToFirstSignificantSubdomainWithWWW('https://news.clickhouse.com.tr/')─┬─cutToFirstSignificantSubdomainWithWWW('www.tr')─┬─cutToFirstSignificantSubdomainWithWWW('tr')─┐
│ clickhouse.com.tr                                                        │ www.tr                                          │                                             │
└──────────────────────────────────────────────────────────────────────────┴─────────────────────────────────────────────────┴─────────────────────────────────────────────┘
```

*Introduced in version 20.12.0.*

cutToFirstSignificantSubdomainWithWWWRFC [#cuttofirstsignificantsubdomainwithwwwrfc]

Returns the part of the domain that includes top-level subdomains up to the "first significant subdomain", without stripping 'www'. Similar to [`cutToFirstSignificantSubdomainWithWWW`](#cutToFirstSignificantSubdomainWithWWW) but conforms to [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986).

**Syntax**

```sql
cutToFirstSignificantSubdomainWithWWWRFC(url)
```

**Arguments**

* `url` — URL or domain string to process according to RFC 3986.

**Returned value**

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

**Examples**

**Usage example**

```sql title=Query
SELECT
    cutToFirstSignificantSubdomainWithWWW('http:%2F%2Fwwwww.nova@mail.ru/economicheskiy'),
    cutToFirstSignificantSubdomainWithWWWRFC('http:%2F%2Fwwwww.nova@mail.ru/economicheskiy');
```

```text title=Response
┌─cutToFirstSignificantSubdomainWithWWW('http:%2F%2Fwwwww.nova@mail.ru/economicheskiy')─┬─cutToFirstSignificantSubdomainWithWWWRFC('http:%2F%2Fwwwww.nova@mail.ru/economicheskiy')─┐
│                                                                                       │ mail.ru                                                                                  │
└───────────────────────────────────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────────────────────────────┘
```

*Introduced in version 22.10.0.*

cutURLParameter [#cuturlparameter]

Removes the first `name=value` occurrence of each requested parameter from a URL.
Only parameters spelled as `name=` are matched, so a value-less flag parameter is left intact, e.g. `cutURLParameter('http://bigmir.net/?a&c=d', 'a')` returns the URL unchanged.
This function does not encode or decode characters in parameter names, e.g. `Client ID` and `Client%20ID` are treated as different parameter names.

**Syntax**

```sql
cutURLParameter(url, name)
```

**Arguments**

* `url` — URL. [`String`](/reference/data-types/string)
* `name` — Name of URL parameter. [`String`](/reference/data-types/string) or [`Array(String)`](/reference/data-types/array)

**Returned value**

URL with the first `name=value` occurrence of each requested parameter removed. [`String`](/reference/data-types/string)

**Examples**

**Usage example**

```sql title=Query
SELECT
    cutURLParameter('http://bigmir.net/?a=b&c=d&e=f#g', 'a') AS url_without_a,
    cutURLParameter('http://bigmir.net/?a=b&c=d&e=f#g', ['c', 'e']) AS url_without_c_and_e;
```

```text title=Response
┌─url_without_a────────────────┬─url_without_c_and_e──────┐
│ http://bigmir.net/?c=d&e=f#g │ http://bigmir.net/?a=b#g │
└──────────────────────────────┴──────────────────────────┘
```

*Introduced in version 1.1.0.*

cutWWW [#cutwww]

Removes the leading `www.`, if present, from the URL's domain.

**Syntax**

```sql
cutWWW(url)
```

**Arguments**

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

**Returned value**

Returns the URL with leading `www.` removed from the domain. [`String`](/reference/data-types/string)

**Examples**

**Usage example**

```sql title=Query
SELECT cutWWW('http://www.example.com/path?query=value#fragment');
```

```text title=Response
┌─cutWWW('http://www.example.com/path?query=value#fragment')─┐
│ http://example.com/path?query=value#fragment               │
└────────────────────────────────────────────────────────────┘
```

*Introduced in version 1.1.0.*

decodeURLComponent [#decodeurlcomponent]

Takes a URL-encoded string as input and decodes it back to its original, readable form.

**Syntax**

```sql
decodeURLComponent(url)
```

**Arguments**

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

**Returned value**

Returns the decoded URL. [`String`](/reference/data-types/string)

**Examples**

**Usage example**

```sql title=Query
SELECT decodeURLComponent('http://127.0.0.1:8123/?query=SELECT%201%3B') AS DecodedURL;
```

```text title=Response
┌─DecodedURL─────────────────────────────┐
│ http://127.0.0.1:8123/?query=SELECT 1; │
└────────────────────────────────────────┘
```

*Introduced in version 1.1.0.*

decodeURLFormComponent [#decodeurlformcomponent]

Decodes URL-encoded strings using form encoding rules ([RFC-1866](https://www.rfc-editor.org/rfc/rfc1866.html)), where `+` signs are converted to spaces and percent-encoded characters are decoded.

**Syntax**

```sql
decodeURLFormComponent(url)
```

**Arguments**

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

**Returned value**

Returns the decoded URL. [`String`](/reference/data-types/string)

**Examples**

**Usage example**

```sql title=Query
SELECT decodeURLFormComponent('http://127.0.0.1:8123/?query=SELECT%201+2%2B3') AS DecodedURL;
```

```text title=Response
┌─DecodedURL────────────────────────────────┐
│ http://127.0.0.1:8123/?query=SELECT 1 2+3 │
└───────────────────────────────────────────┘
```

*Introduced in version 1.1.0.*

domain [#domain]

Extracts the hostname from a URL.

The URL can be specified with or without a protocol.

**Syntax**

```sql
domain(url)
```

**Arguments**

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

**Returned value**

Returns the host name if the input string can be parsed as a URL, otherwise an empty string. [`String`](/reference/data-types/string)

**Examples**

**Usage example**

```sql title=Query
SELECT domain('svn+ssh://some.svn-hosting.com:80/repo/trunk');
```

```text title=Response
┌─domain('svn+ssh://some.svn-hosting.com:80/repo/trunk')─┐
│ some.svn-hosting.com                                   │
└────────────────────────────────────────────────────────┘
```

*Introduced in version 1.1.0.*

domainRFC [#domainrfc]

Extracts the hostname from a URL.
Similar to [`domain`](#domain), but [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986) conformant.

**Syntax**

```sql
domainRFC(url)
```

**Arguments**

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

**Returned value**

Returns the host name if the input string can be parsed as a URL, otherwise an empty string. [`String`](/reference/data-types/string)

**Examples**

**Usage example**

```sql title=Query
SELECT
    domain('http://user:password@example.com:8080/path?query=value#fragment'),
    domainRFC('http://user:password@example.com:8080/path?query=value#fragment');
```

```text title=Response
┌─domain('http://user:password@example.com:8080/path?query=value#fragment')─┬─domainRFC('http://user:password@example.com:8080/path?query=value#fragment')─┐
│                                                                           │ example.com                                                                  │
└───────────────────────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────────────────┘
```

*Introduced in version 22.10.0.*

domainWithoutWWW [#domainwithoutwww]

Returns the domain of a URL without leading `www.` if present.

**Syntax**

```sql
domainWithoutWWW(url)
```

**Arguments**

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

**Returned value**

Returns the domain name if the input string can be parsed as a URL (without leading `www.`), otherwise an empty string. [`String`](/reference/data-types/string)

**Examples**

**Usage example**

```sql title=Query
SELECT domainWithoutWWW('http://paul@www.example.com:80/');
```

```text title=Response
┌─domainWithoutWWW('http://paul@www.example.com:80/')─┐
│ example.com                                         │
└─────────────────────────────────────────────────────┘
```

*Introduced in version 1.1.0.*

domainWithoutWWWRFC [#domainwithoutwwwrfc]

Returns the domain without leading `www.` if present. Similar to [`domainWithoutWWW`](#domainWithoutWWW) but conforms to [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986).

**Syntax**

```sql
domainWithoutWWWRFC(url)
```

**Arguments**

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

**Returned value**

Returns the domain name if the input string can be parsed as a URL (without leading `www.`), otherwise an empty string. [`String`](/reference/data-types/string)

**Examples**

**Usage example**

```sql title=Query
SELECT
    domainWithoutWWW('http://user:password@www.example.com:8080/path?query=value#fragment'),
    domainWithoutWWWRFC('http://user:password@www.example.com:8080/path?query=value#fragment');
```

```text title=Response
┌─domainWithoutWWW('http://user:password@www.example.com:8080/path?query=value#fragment')─┬─domainWithoutWWWRFC('http://user:password@www.example.com:8080/path?query=value#fragment')─┐
│                                                                                         │ example.com                                                                                │
└─────────────────────────────────────────────────────────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────────────┘
```

*Introduced in version 1.1.0.*

encodeURLComponent [#encodeurlcomponent]

Takes a regular string and converts it into a URL-encoded (percent-encoded) format where special characters are replaced with their percent-encoded equivalents.

**Syntax**

```sql
encodeURLComponent(url)
```

**Arguments**

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

**Returned value**

Returns the encoded URL. [`String`](/reference/data-types/string)

**Examples**

**Usage example**

```sql title=Query
SELECT encodeURLComponent('http://127.0.0.1:8123/?query=SELECT 1;') AS EncodedURL;
```

```text title=Response
┌─EncodedURL───────────────────────────────────────────────┐
│ https%3A%2F%2Fsiteproxy.ruqli.workers.dev%3A443%2Fhttp%2F127.0.0.1%3A8123%2F%3Fquery%3DSELECT%201%3B │
└──────────────────────────────────────────────────────────┘
```

*Introduced in version 22.3.0.*

encodeURLFormComponent [#encodeurlformcomponent]

Encodes strings using form encoding rules ([RFC-1866](https://www.rfc-editor.org/rfc/rfc1866.html)), where spaces are converted to + signs and special characters are percent-encoded.

**Syntax**

```sql
encodeURLFormComponent(url)
```

**Arguments**

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

**Returned value**

Returns the encoded URL. [`String`](/reference/data-types/string)

**Examples**

**Usage example**

```sql title=Query
SELECT encodeURLFormComponent('http://127.0.0.1:8123/?query=SELECT 1 2+3') AS EncodedURL;
```

```text title=Response
┌─EncodedURL────────────────────────────────────────────────┐
│ https%3A%2F%2Fsiteproxy.ruqli.workers.dev%3A443%2Fhttp%2F127.0.0.1%3A8123%2F%3Fquery%3DSELECT+1+2%2B3 │
└───────────────────────────────────────────────────────────┘
```

*Introduced in version 22.3.0.*

extractURLParameter [#extracturlparameter]

Returns the value of the `name` parameter in the URL, if present, otherwise an empty string is returned.
If there are multiple parameters with this name, the first occurrence is returned.
The function assumes that the parameter in the `url` parameter is encoded in the same way as in the `name` argument.

**Syntax**

```sql
extractURLParameter(url, name)
```

**Arguments**

* `url` — URL. [`String`](/reference/data-types/string)
* `name` — Parameter name. [`String`](/reference/data-types/string)

**Returned value**

Returns the value of the URL parameter with the specified name. [`String`](/reference/data-types/string)

**Examples**

**Usage example**

```sql title=Query
SELECT extractURLParameter('http://example.com/?param1=value1&param2=value2', 'param1');
```

```text title=Response
┌─extractURLPa⋯, 'param1')─┐
│ value1                   │
└──────────────────────────┘
```

*Introduced in version 1.1.0.*

extractURLParameterNames [#extracturlparameternames]

Returns an array of name strings corresponding to the names of URL parameters.
The values are not decoded.

**Syntax**

```sql
extractURLParameterNames(url)
```

**Arguments**

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

**Returned value**

Returns an array of name strings corresponding to the names of URL parameters. [`Array(String)`](/reference/data-types/array)

**Examples**

**Usage example**

```sql title=Query
SELECT extractURLParameterNames('http://example.com/?param1=value1&param2=value2');
```

```text title=Response
┌─extractURLPa⋯m2=value2')─┐
│ ['param1','param2']      │
└──────────────────────────┘
```

*Introduced in version 1.1.0.*

extractURLParameters [#extracturlparameters]

Returns an array of `name=value` strings corresponding to the URL parameters.
The values are not decoded.

**Syntax**

```sql
extractURLParameters(url)
```

**Arguments**

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

**Returned value**

Returns an array of `name=value` strings corresponding to the URL parameters. [`Array(String)`](/reference/data-types/array)

**Examples**

**Usage example**

```sql title=Query
SELECT extractURLParameters('http://example.com/?param1=value1&param2=value2');
```

```text title=Response
┌─extractURLParame⋯&param2=value2')─┐
│ ['param1=value1','param2=value2'] │
└───────────────────────────────────┘
```

*Introduced in version 1.1.0.*

firstSignificantSubdomain [#firstsignificantsubdomain]

Returns the "first significant subdomain".

The first significant subdomain is a second-level domain if it is 'com', 'net', 'org', or 'co'.
Otherwise, it is a third-level domain.

For example, firstSignificantSubdomain('[https://news.clickhouse.com/](https://news.clickhouse.com/)') = 'clickhouse', firstSignificantSubdomain ('[https://news.clickhouse.com.tr/](https://news.clickhouse.com.tr/)') = 'clickhouse'.

The list of "insignificant" second-level domains and other implementation details may change in the future.

**Syntax**

```sql
firstSignificantSubdomain(url)
```

**Examples**

**firstSignificantSubdomain**

```sql title=Query
SELECT firstSignificantSubdomain('https://news.clickhouse.com/')
```

*Introduced in version 1.1.0.*

firstSignificantSubdomainCustom [#firstsignificantsubdomaincustom]

Returns the first significant subdomain of a URL using a custom TLD (Top-Level Domain) list. The custom TLD list name refers to a configuration that defines which domain suffixes should be treated as top-level domains. This is useful for non-standard TLD hierarchies. The function uses a simplified URL parsing algorithm that assumes the protocol and everything following are stripped.

**Syntax**

```sql
firstSignificantSubdomainCustom(url, tld_list_name)
```

**Arguments**

* `url` — The URL to extract the subdomain from. [`String`](/reference/data-types/string)
* `tld_list_name` — Name of the custom TLD list from the configuration. [`String`](/reference/data-types/string)

**Returned value**

Returns the first significant subdomain. [`String`](/reference/data-types/string)

**Examples**

**Basic usage**

```sql title=Query
SELECT firstSignificantSubdomainCustom('https://news.example.com', 'public_suffix_list')
```

```text title=Response
example
```

*Introduced in version 21.1.0.*

firstSignificantSubdomainCustomRFC [#firstsignificantsubdomaincustomrfc]

Similar to `firstSignificantSubdomainCustom` but uses RFC 3986 compliant URL parsing instead of the simplified algorithm.

**Syntax**

```sql
firstSignificantSubdomainCustomRFC(url, tld_list_name)
```

**Arguments**

* `url` — The URL to extract the subdomain from. [`String`](/reference/data-types/string)
* `tld_list_name` — Name of the custom TLD list from the configuration. [`String`](/reference/data-types/string)

**Returned value**

Returns the first significant subdomain. [`String`](/reference/data-types/string)

**Examples**

**Basic usage**

```sql title=Query
SELECT firstSignificantSubdomainCustomRFC('https://news.example.com', 'public_suffix_list')
```

```text title=Response
example
```

*Introduced in version 22.10.0.*

firstSignificantSubdomainRFC [#firstsignificantsubdomainrfc]

Returns the "first significant subdomain" according to RFC 1034.

**Syntax**

```sql
firstSignificantSubdomainRFC(url)
```

*Introduced in version 22.10.0.*

fragment [#fragment]

Returns the fragment identifier without the initial hash symbol.

**Syntax**

```sql
fragment(url)
```

**Arguments**

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

**Returned value**

Returns the fragment identifier without the initial hash symbol. [`String`](/reference/data-types/string)

**Examples**

**Usage example**

```sql title=Query
SELECT fragment('https://clickhouse.com/docs/get-started/setup/cloud#1-create-a-clickhouse-service');
```

```text title=Response
┌─fragment('http⋯ouse-service')─┐
│ 1-create-a-clickhouse-service │
└───────────────────────────────┘
```

*Introduced in version 1.1.0.*

netloc [#netloc]

Extracts network locality (`username:password@host:port`) from a URL.

**Syntax**

```sql
netloc(url)
```

**Arguments**

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

**Returned value**

Returns `username:password@host:port` from a given URL. [`String`](/reference/data-types/string)

**Examples**

**Usage example**

```sql title=Query
SELECT netloc('http://paul@www.example.com:80/');
```

```text title=Response
┌─netloc('http⋯e.com:80/')─┐
│ paul@www.example.com:80  │
└──────────────────────────┘
```

*Introduced in version 20.5.0.*

path [#path]

Returns the path without query string from a URL.

**Syntax**

```sql
path(url)
```

**Arguments**

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

**Returned value**

Returns the path of the URL without query string. [`String`](/reference/data-types/string)

**Examples**

**Usage example**

```sql title=Query
SELECT path('https://clickhouse.com/docs/reference/functions/regular-functions/url-functions?query=value');
```

```text title=Response
┌─path('https://clickhouse.com/en/sql-reference/functions/url-functions/?query=value')─┐
│ /docs/sql-reference/functions/url-functions/                                         │
└──────────────────────────────────────────────────────────────────────────────────────┘
```

*Introduced in version 1.1.0.*

pathFull [#pathfull]

The same as [`path`](#path), but includes the query string and fragment of the URL.

**Syntax**

```sql
pathFull(url)
```

**Arguments**

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

**Returned value**

Returns the path of the URL including query string and fragment. [`String`](/reference/data-types/string)

**Examples**

**Usage example**

```sql title=Query
SELECT pathFull('https://clickhouse.com/docs/reference/functions/regular-functions/url-functions?query=value#section');
```

```text title=Response
┌─pathFull('https://clickhouse.com⋯unctions/?query=value#section')─┐
│ /docs/sql-reference/functions/url-functions/?query=value#section │
└──────────────────────────────────────────────────────────────────┘
```

*Introduced in version 1.1.0.*

port [#port]

Returns the port of a URL, or the `default_port` if the URL contains no port or cannot be parsed.

**Syntax**

```sql
port(url[, default_port])
```

**Arguments**

* `url` — URL. [`String`](/reference/data-types/string)
* `default_port` — Optional. The default port number to be returned. `0` by default. [`UInt16`](/reference/data-types/int-uint)

**Returned value**

Returns the port of the URL, or the default port if there is no port in the URL or in case of a validation error. [`UInt16`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT port('https://clickhouse.com:8443/docs'), port('https://clickhouse.com/docs', 443);
```

```text title=Response
┌─port('https://clickhouse.com:8443/docs')─┬─port('https://clickhouse.com/docs', 443)─┐
│                                     8443 │                                      443 │
└──────────────────────────────────────────┴──────────────────────────────────────────┘
```

*Introduced in version 20.5.0.*

portRFC [#portrfc]

Returns the port or `default_port` if the URL contains no port or cannot be parsed.
Similar to [`port`](#port), but [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986) conformant.

**Syntax**

```sql
portRFC(url[, default_port])
```

**Arguments**

* `url` — URL. [`String`](/reference/data-types/string)
* `default_port` — Optional. The default port number to be returned. `0` by default. [`UInt16`](/reference/data-types/int-uint)

**Returned value**

Returns the port or the default port if there is no port in the URL or in case of a validation error. [`UInt16`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT port('http://user:password@example.com:8080/'), portRFC('http://user:password@example.com:8080/');
```

```text title=Response
┌─port('http:/⋯com:8080/')─┬─portRFC('htt⋯com:8080/')─┐
│                        0 │                     8080 │
└──────────────────────────┴──────────────────────────┘
```

*Introduced in version 22.10.0.*

protocol [#protocol]

Extracts the protocol from a URL.

Examples of typical returned values: http, https, ftp, mailto, tel, magnet.

**Syntax**

```sql
protocol(url)
```

**Arguments**

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

**Returned value**

Returns the protocol of the URL, or an empty string if it cannot be determined. [`String`](/reference/data-types/string)

**Examples**

**Usage example**

```sql title=Query
SELECT protocol('https://clickhouse.com/');
```

```text title=Response
┌─protocol('https://clickhouse.com/')─┐
│ https                               │
└─────────────────────────────────────┘
```

*Introduced in version 1.1.0.*

queryString [#querystring]

Returns the query string of a URL without the initial question mark, `#` and everything after `#`.

**Syntax**

```sql
queryString(url)
```

**Arguments**

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

**Returned value**

Returns the query string of the URL without the initial question mark and fragment. [`String`](/reference/data-types/string)

**Examples**

**Usage example**

```sql title=Query
SELECT queryString('https://clickhouse.com/docs?query=value&param=123#section');
```

```text title=Response
┌─queryString(⋯3#section')─┐
│ query=value&param=123    │
└──────────────────────────┘
```

*Introduced in version 1.1.0.*

queryStringAndFragment [#querystringandfragment]

Returns the query string and fragment identifier of a URL.

**Syntax**

```sql
queryStringAndFragment(url)
```

**Arguments**

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

**Returned value**

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

**Examples**

**Usage example**

```sql title=Query
SELECT queryStringAndFragment('https://clickhouse.com/docs?query=value&param=123#section');
```

```text title=Response
┌─queryStringAnd⋯=123#section')─┐
│ query=value&param=123#section │
└───────────────────────────────┘
```

*Introduced in version 1.1.0.*

topLevelDomain [#topleveldomain]

Extracts the the top-level domain from a URL.

:::note
The URL can be specified with or without a protocol.
For example:

```text
svn+ssh://some.svn-hosting.com:80/repo/trunk
some.svn-hosting.com:80/repo/trunk
https://clickhouse.com/time/
```

:::

**Syntax**

```sql
topLevelDomain(url)
```

**Arguments**

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

**Returned value**

Returns the domain name if the input string can be parsed as a URL. Otherwise, an empty string. [`String`](/reference/data-types/string)

**Examples**

**Usage example**

```sql title=Query
SELECT topLevelDomain('svn+ssh://www.some.svn-hosting.com:80/repo/trunk');
```

```text title=Response
┌─topLevelDomain('svn+ssh://www.some.svn-hosting.com:80/repo/trunk')─┐
│ com                                                                │
└────────────────────────────────────────────────────────────────────┘
```

*Introduced in version 1.1.0.*

topLevelDomainRFC [#topleveldomainrfc]

Extracts the the top-level domain from a URL.
Similar to [`topLevelDomain`](#topLevelDomain), but conforms to [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986).

**Syntax**

```sql
topLevelDomainRFC(url)
```

**Arguments**

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

**Returned value**

Domain name if the input string can be parsed as a URL. Otherwise, an empty string. [`String`](/reference/data-types/string)

**Examples**

**Usage example**

```sql title=Query
SELECT topLevelDomain('http://foo:foo%41bar@foo.com'), topLevelDomainRFC('http://foo:foo%41bar@foo.com');
```

```text title=Response
┌─topLevelDomain('http://foo:foo%41bar@foo.com')─┬─topLevelDomainRFC('http://foo:foo%41bar@foo.com')─┐
│                                                │ com                                               │
└────────────────────────────────────────────────┴───────────────────────────────────────────────────┘
```

*Introduced in version 22.10.0.*
