Functions for working with URLs

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

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

**Examples**

**Usage example**

```
SELECT netloc('http://[email protected]:80/');
```

```
┌─netloc('http⋯e.com:80/')─┐
│ [email protected]:80  │
└──────────────────────────┘
```

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

Introduced in: v1.1.0

Returns the path without query string from a URL.

**Syntax**

```
path(url)
```

**Arguments**

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

**Returned value**

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

**Examples**

**Usage example**

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

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

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

Introduced in: v1.1.0

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

**Syntax**

```
pathFull(url)
```

**Arguments**

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

**Returned value**

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

**Examples**

**Usage example**

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

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

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

Introduced in: v20.5.0

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

**Syntax**

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

**Arguments**

- `url` — URL. [`String`](/docs/sql-reference/data-types/string)
- `default_port` — Optional. The default port number to be returned. `0` by default. [`UInt16`](/docs/sql-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`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

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

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

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

Introduced in: v22.10.0

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

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

**Arguments**

- `url` — URL. [`String`](/docs/sql-reference/data-types/string)
- `default_port` — Optional. The default port number to be returned. `0` by default. [`UInt16`](/docs/sql-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`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT port('http://user:[email protected]:8080/'), portRFC('http://user:[email protected]:8080/');
```

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

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

Introduced in: v1.1.0

Extracts the protocol from a URL.

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

**Syntax**

```
protocol(url)
```

**Arguments**

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

**Returned value**

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

**Examples**

**Usage example**

```
SELECT protocol('https://clickhouse.com/');
```

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

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

Introduced in: v1.1.0

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

**Syntax**

```
queryString(url)
```

**Arguments**

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

**Returned value**

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

**Examples**

**Usage example**

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

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

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

Introduced in: v1.1.0

Returns the query string and fragment identifier of a URL.

**Syntax**

```
queryStringAndFragment(url)
```

**Arguments**

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

**Returned value**

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

**Examples**

**Usage example**

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

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

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

Introduced in: v1.1.0

Extracts the the top-level domain from a URL.

Note

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

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

**Syntax**

```
topLevelDomain(url)
```

**Arguments**

- `url` — URL. [`String`](/docs/sql-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`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

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

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

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

Introduced in: v22.10.0

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

```
topLevelDomainRFC(url)
```

**Arguments**

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

**Returned value**