Functions for working with URLs

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

Introduced in: v22.3.0

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

```
encodeURLComponent(url)
```

**Arguments**

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

**Returned value**

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

**Examples**

**Usage example**

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

```
┌─EncodedURL───────────────────────────────────────────────┐
│ http%3A%2F%2F127.0.0.1%3A8123%2F%3Fquery%3DSELECT%201%3B │
└──────────────────────────────────────────────────────────┘
```

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

Introduced in: v22.3.0

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

```
encodeURLFormComponent(url)
```

**Arguments**

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

**Returned value**

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

**Examples**

**Usage example**

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

```
┌─EncodedURL────────────────────────────────────────────────┐
│ http%3A%2F%2F127.0.0.1%3A8123%2F%3Fquery%3DSELECT+1+2%2B3 │
└───────────────────────────────────────────────────────────┘
```

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

Introduced in: v1.1.0

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

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

**Arguments**

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

**Returned value**

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

**Examples**

**Usage example**

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

```
┌─extractURLPa⋯, 'param1')─┐
│ value1                   │
└──────────────────────────┘
```

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

Introduced in: v1.1.0

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

**Syntax**

```
extractURLParameterNames(url)
```

**Arguments**

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

**Returned value**

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

**Examples**

**Usage example**

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

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

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

Introduced in: v1.1.0

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

**Syntax**

```
extractURLParameters(url)
```

**Arguments**

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

**Returned value**

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

**Examples**

**Usage example**

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

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

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

Introduced in: v1.1.0

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/>') = 'clickhouse', firstSignificantSubdomain ('<https://news.clickhouse.com.tr/>') = 'clickhouse'.

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

**Syntax**

```
firstSignificantSubdomain(url)
```

**Arguments**

- None.

**Returned value**

**Examples**

**firstSignificantSubdomain**

```
SELECT firstSignificantSubdomain('https://news.clickhouse.com/')
```

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

Introduced in: v21.1.0

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

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

**Arguments**

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

**Returned value**

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

**Examples**

**Basic usage**

```
SELECT firstSignificantSubdomainCustom('https://news.example.com', 'public_suffix_list')
```

```
example
```

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

Introduced in: v22.10.0

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

**Syntax**

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

**Arguments**

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

**Returned value**

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

**Examples**

**Basic usage**

```
SELECT firstSignificantSubdomainCustomRFC('https://news.example.com', 'public_suffix_list')
```

```
example
```

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

Introduced in: v22.10.0

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

**Syntax**

```
firstSignificantSubdomainRFC(url)
```

**Arguments**

- None.

**Returned value**

**Examples**

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

Introduced in: v1.1.0

Returns the fragment identifier without the initial hash symbol.

**Syntax**

```
fragment(url)
```

**Arguments**

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

**Returned value**

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

**Examples**

**Usage example**

```
SELECT fragment('https://clickhouse.com/docs/getting-started/quick-start/cloud#1-create-a-clickhouse-service');
```

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

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

Introduced in: v20.5.0

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

**Syntax**

```
netloc(url)
```

**Arguments**

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

**Returned value**