概述
处理既不包含用户信息字符串也不包含 @ 符号的公开注册域名时,通常可以使用非 RFC 函数变体。
下表详细列出了 URL 中哪些符号可以 (✔) 或不可以 (✗) 被相应的 RFC 和非 RFC 变体解析:
| Symbol | non-RFC |
RFC |
|
|---|---|---|---|
| ' ' | ✗ | ✗ | |
| \t | ✗ | ✗ | |
| < | ✗ | ✗ | |
| > | ✗ | ✗ | |
| % | ✗ | ✔* | |
| { | ✗ | ✗ | |
| } | ✗ | ✗ | |
| ✗ | ✗ | ||
| \ | ✗ | ✗ | |
| ^ | ✗ | ✗ | |
| ~ | ✗ | ✔* | |
| [ | ✗ | ✗ | |
| ] | ✗ | ✔ | |
| ; | ✗ | ✔* | |
| = | ✗ | ✔* | |
| & | ✗ | ✔* |
标有 * 的符号是 RFC 3986 中的子分隔符,允许用于 @ 符号后的用户信息。
URL 函数分为两类:
- 提取 URL 各部分的函数。如果 URL 中不存在相应部分,则返回空字符串。
- 移除 URL 某一部分的函数。如果 URL 中没有对应内容,则 URL 保持不变。
URLHierarchy
Introduced in: v1.1.0
返回一个数组,其中包含按层级截断的 URL:在 path 和查询字符串中,以 /、? 和 # 为分隔符从末尾逐级截断。连续的分隔符字符按一个计算。结果的第一个元素包含协议和主机,后续元素则通过逐步延长路径形成层级结构。
语法
URLHierarchy(url)参数
url— 要处理的 URL。String
返回值
返回一个由长度逐步增加的 URL 组成的层级数组。Array(String)
示例
基本用法
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
引入版本:v1.1.0
返回一个数组,其中包含 URL 的路径部分,并在末尾以 /、? 和 # 为截断符。与 URLHierarchy 不同,结果不包含协议和主机,而是从路径开始。连续的分隔符会视为一个。
语法
URLPathHierarchy(url)参数
url— 要处理的 URL。String
返回值
返回一个数组,其中包含按层级逐步变长的 URL 路径部分。Array(String)
示例
基本用法
SELECT URLPathHierarchy('https://example.com/a/b?c=1')['/a/','/a/b?','/a/b?c=1']cutFragment
引入版本:v1.1.0
从 URL 中移除片段标识符,包括井号 (#) 。
语法
cutFragment(url)参数
url— URL。String
返回值
返回去除了片段标识符的 URL。String
示例
使用示例
SELECT cutFragment('http://example.com/path?query=value#fragment123');┌─cutFragment('http://example.com/path?query=value#fragment123')─┐
│ http://example.com/path?query=value │
└────────────────────────────────────────────────────────────────┘cutQueryString
引入版本:v1.1.0
从 URL 中去掉查询字符串 (包括问号) 。
语法
cutQueryString(url)参数
url— URL。String
返回值
返回移除查询字符串后的 URL。String
示例
使用示例
SELECT cutQueryString('http://example.com/path?query=value¶m=123#fragment');┌─cutQueryString('http://example.com/path?query=value¶m=123#fragment')─┐
│ http://example.com/path#fragment │
└──────────────────────────────────────────────────────────────────────────┘cutQueryStringAndFragment
在 v1.1.0 中引入
从 URL 中移除查询字符串和片段标识符,包括问号和井号。
语法
cutQueryStringAndFragment(url)参数
url— URL。String
返回值
返回去除了查询字符串和片段标识符的 URL。String
示例
使用示例
SELECT cutQueryStringAndFragment('http://example.com/path?query=value¶m=123#fragment');┌─cutQueryStringAndFragment('http://example.com/path?query=value¶m=123#fragment')─┐
│ http://example.com/path │
└─────────────────────────────────────────────────────────────────────────────────────┘cutToFirstSignificantSubdomain
引入版本:v1.1.0
返回域名中从顶级子域开始,直到第一个有效子域 (含) 的部分。
语法
cutToFirstSignificantSubdomain(url)参数
url— 要处理的 URL 或域名字符串。String
返回值
如果可能,返回域名中从顶级子域到第一个有效子域的部分;否则返回空字符串。String
示例
用法示例
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
引入版本:v21.1.0
返回域名中从顶级子域开始直到第一个有效子域的部分。接受自定义的 TLD 列表 名称。如果你需要最新的 TLD 列表,或者有自定义列表,此函数会很有用。
配置示例
<!-- <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>
<!-- 注意:path 位于 top_level_domains_path 下 -->
</top_level_domains_lists>语法
cutToFirstSignificantSubdomainCustom(url, tld_list_name)参数
url— 要处理的 URL 或域名字符串。Stringtld_list_name— 在 ClickHouse 中配置的自定义 TLD 列表的名称。const String
返回值
返回域名中从顶级子域开始、直到第一个有效子域为止的部分。String
示例
对非标准域名使用自定义 TLD 列表
SELECT cutToFirstSignificantSubdomainCustom('bar.foo.there-is-no-such-domain', 'public_suffix_list')foo.there-is-no-such-domaincutToFirstSignificantSubdomainCustomRFC
引入版本:v22.10.0
返回域名中从顶级子域到第一个有效子域的部分。 接受自定义的 TLD 列表 名称。 如果你需要最新的 TLD 列表,或者使用自定义列表,此函数会很有用。 与 cutToFirstSignificantSubdomainCustom 类似,但符合 RFC 3986。
配置示例
<!-- <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>语法
cutToFirstSignificantSubdomainCustomRFC(url, tld_list_name)参数
url— 按照 RFC 3986 处理的 URL 或域名字符串。 -tld_list_name— 在 ClickHouse 中配置的自定义 TLD 列表名称。
返回值
返回域名中从顶级子域到第一个有效子域这一部分。String
示例
用法示例
SELECT cutToFirstSignificantSubdomainCustomRFC('www.foo', 'public_suffix_list');┌─cutToFirstSignificantSubdomainCustomRFC('www.foo', 'public_suffix_list')─┐
│ foo │
└──────────────────────────────────────────────────────────────────────────┘cutToFirstSignificantSubdomainCustomWithWWW
引入版本:v21.1.0
返回域名中从顶级子域到第一个有效子域的部分,且不会去除 'www'。接受自定义 TLD 列表名称。如果你需要最新的 TLD 列表,或者使用自定义列表,此函数会很有用。
配置示例
<!-- <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>
<!-- 注意:path 位于 top_level_domains_path 下 -->
</top_level_domains_lists>
**Syntax**
```sql
cutToFirstSignificantSubdomainCustomWithWWW(url, tld_list_name)参数
url— 要处理的 URL 或域名字符串。 -tld_list_name— 在 ClickHouse 中配置的自定义 TLD 列表名称。
返回值
域名中从顶级子域到第一个有效子域的部分,且不会移除 'www'。 String
示例
使用示例
SELECT cutToFirstSignificantSubdomainCustomWithWWW('www.foo', 'public_suffix_list');┌─cutToFirstSignificantSubdomainCustomWithWWW('www.foo', 'public_suffix_list')─┐
│ www.foo │
└──────────────────────────────────────────────────────────────────────────────┘cutToFirstSignificantSubdomainCustomWithWWWRFC
引入版本:v22.10.0
返回域名中从顶级子域到第一个有效子域的部分,且不会去除 www。
接受自定义 TLD 列表名称。
如果你需要较新的 TLD 列表,或者使用自定义列表,此函数会很有用。
与 cutToFirstSignificantSubdomainCustomWithWWW 类似,但遵循 RFC 3986。
配置示例
{/* <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>
**语法**
```sql
cutToFirstSignificantSubdomainCustomWithWWWRFC(url, tld_list_name)参数
url— 要按照 RFC 3986 处理的 URL 或域名字符串。 -tld_list_name— 在 ClickHouse 中配置的自定义 TLD 列表名称。
返回值
返回域名中从顶级子域到第一个有效子域的部分,且不会去除 www。String
示例
使用自定义 TLD 列表按 RFC 3986 解析并保留 www
SELECT cutToFirstSignificantSubdomainCustomWithWWWRFC('https://www.subdomain.example.custom', 'public_suffix_list')example.customcutToFirstSignificantSubdomainRFC
Introduced in:v22.10.0
返回域名中从顶级子域开始直到“第一个有效子域”的部分。与 cutToFirstSignificantSubdomain 类似,但遵循 RFC 3986。
Syntax
cutToFirstSignificantSubdomainRFC(url)参数
url— 要按 RFC 3986 处理的 URL 或域名字符串。String
返回值
如果可能,返回域名中从顶级子域开始直到第一个有效子域 (含) 的部分;否则返回空字符串。String
示例
使用示例
SELECT
cutToFirstSignificantSubdomain('http://user:password@example.com:8080'),
cutToFirstSignificantSubdomainRFC('http://user:password@example.com:8080');┌─cutToFirstSignificantSubdomain('http://user:password@example.com:8080')─┬─cutToFirstSignificantSubdomainRFC('http://user:password@example.com:8080')─┐
│ │ example.com │
└─────────────────────────────────────────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────┘cutToFirstSignificantSubdomainWithWWW
引入版本:v20.12.0
返回域名中从顶级子域到“第一个有效子域”的部分,且不会去除 www.。
与 cutToFirstSignificantSubdomain 类似,但如果存在 www. 前缀,则会保留它。
语法
cutToFirstSignificantSubdomainWithWWW(url)参数
url— 要处理的 URL 或域名字符串。String
返回值
返回域名中从顶级子域开始、直到第一个有效子域为止的部分 (如可能则包含 www) ;否则返回空字符串。String
示例
用法示例
SELECT
cutToFirstSignificantSubdomainWithWWW('https://news.clickhouse.com.tr/'),
cutToFirstSignificantSubdomainWithWWW('www.tr'),
cutToFirstSignificantSubdomainWithWWW('tr');┌─cutToFirstSignificantSubdomainWithWWW('https://news.clickhouse.com.tr/')─┬─cutToFirstSignificantSubdomainWithWWW('www.tr')─┬─cutToFirstSignificantSubdomainWithWWW('tr')─┐
│ clickhouse.com.tr │ www.tr │ │
└──────────────────────────────────────────────────────────────────────────┴─────────────────────────────────────────────────┴─────────────────────────────────────────────┘cutToFirstSignificantSubdomainWithWWWRFC
引入版本:v22.10.0
返回域名中从顶级子域到“第一个有效子域”为止的部分,且不会去除 'www'。与 cutToFirstSignificantSubdomainWithWWW 类似,但符合 RFC 3986。
语法
cutToFirstSignificantSubdomainWithWWWRFC(url)参数
url— 按照 RFC 3986 处理的 URL 或域名字符串。
返回值
如果可能,返回域名中从顶级子域开始直到第一个有效子域 (包括 'www') 的部分;否则返回空字符串 String
示例
用法示例
SELECT
cutToFirstSignificantSubdomainWithWWW('http:%2F%2Fwwwww.nova@mail.ru/economicheskiy'),
cutToFirstSignificantSubdomainWithWWWRFC('http:%2F%2Fwwwww.nova@mail.ru/economicheskiy');┌─cutToFirstSignificantSubdomainWithWWW('http:%2F%2Fwwwww.nova@mail.ru/economicheskiy')─┬─cutToFirstSignificantSubdomainWithWWWRFC('http:%2F%2Fwwwww.nova@mail.ru/economicheskiy')─┐
│ │ mail.ru │
└───────────────────────────────────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────────────────────────────┘cutURLParameter
引入版本:v1.1.0
从 URL 中移除每个请求参数首次出现的 name=value。
仅匹配拼写为 name= 的参数,因此不带值的标志参数会保持不变,例如,cutURLParameter('http://bigmir.net/?a&c=d', 'a') 会原样返回该 URL。
此函数不会对参数名称中的字符进行编码或解码,例如,Client ID 和 Client%20ID 会被视为不同的参数名称。
语法
cutURLParameter(url, name)参数
url— URL。Stringname— URL 参数名。String或Array(String)
返回值
移除每个指定参数首次出现的 name=value 后的 URL。String
示例
用法示例
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;┌─url_without_a────────────────┬─url_without_c_and_e───────┐
│ http://bigmir.net/?c=d&e=f#g │ http://bigmir.net/?a=b&#g │
└──────────────────────────────┴───────────────────────────┘cutWWW
引入版本:v1.1.0
如果 URL 的域名以 www. 开头,则将其移除。
语法
cutWWW(url)参数
url— URL。String
返回值
返回去除域名前导 www. 后的 URL。 String
示例
用法示例
SELECT cutWWW('http://www.example.com/path?query=value#fragment');┌─cutWWW('http://www.example.com/path?query=value#fragment')─┐
│ http://example.com/path?query=value#fragment │
└────────────────────────────────────────────────────────────┘decodeURLComponent
引入版本:v1.1.0
接受一个经过 URL 编码的字符串作为输入,并将其解码为原始的可读形式。
语法
decodeURLComponent(url)参数
url— URL。String
返回值
返回解码后的 URL。 String
示例
使用示例
SELECT decodeURLComponent('http://127.0.0.1:8123/?query=SELECT%201%3B') AS DecodedURL;┌─DecodedURL─────────────────────────────┐
│ http://127.0.0.1:8123/?query=SELECT 1; │
└────────────────────────────────────────┘decodeURLFormComponent
引入于:v1.1.0
使用表单编码规则 (RFC-1866) 对 URL 编码字符串进行解码,其中 + 号会转换为空格,百分号编码的字符也会被解码。
语法
decodeURLFormComponent(url)参数
url— URL。String
返回值
返回解码后的 URL。 String
示例
使用示例
SELECT decodeURLFormComponent('http://127.0.0.1:8123/?query=SELECT%201+2%2B3') AS DecodedURL;┌─DecodedURL────────────────────────────────┐
│ http://127.0.0.1:8123/?query=SELECT 1 2+3 │
└───────────────────────────────────────────┘domain
引入版本:v1.1.0
从 URL 中提取主机名。
URL 可以带协议,也可以不带协议。
语法
domain(url)参数
url— URL。String
返回值
如果输入字符串可解析为 URL,则返回主机名;否则返回空字符串。String
示例
用法示例
SELECT domain('svn+ssh://some.svn-hosting.com:80/repo/trunk');┌─domain('svn+ssh://some.svn-hosting.com:80/repo/trunk')─┐
│ some.svn-hosting.com │
└────────────────────────────────────────────────────────┘domainRFC
引入版本:v22.10.0
从 URL 中提取主机名。
与 domain 类似,但遵循 RFC 3986 规范。
语法
domainRFC(url)参数
url— URL。String
返回值
如果输入字符串可解析为 URL,则返回主机名;否则返回空字符串。 String
示例
使用示例
SELECT
domain('http://user:password@example.com:8080/path?query=value#fragment'),
domainRFC('http://user:password@example.com:8080/path?query=value#fragment');┌─domain('http://user:password@example.com:8080/path?query=value#fragment')─┬─domainRFC('http://user:password@example.com:8080/path?query=value#fragment')─┐
│ │ example.com │
└───────────────────────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────────────────┘domainWithoutWWW
引入版本:v1.1.0
返回 URL 的域名;如果存在前缀 www.,则将其去除。
语法
domainWithoutWWW(url)参数
url— URL。String
返回值
若输入字符串可解析为 URL (不含前导 www.) ,则返回域名;否则返回空字符串。String
示例
使用示例
SELECT domainWithoutWWW('http://paul@www.example.com:80/');┌─domainWithoutWWW('http://paul@www.example.com:80/')─┐
│ example.com │
└─────────────────────────────────────────────────────┘domainWithoutWWWRFC
引入版本:v1.1.0
如果存在前导 www.,则返回去掉此前导部分的域名。与 domainWithoutWWW 类似,但符合 RFC 3986。
语法
domainWithoutWWWRFC(url)参数
url— URL。String
返回值
如果输入字符串可解析为 URL,则返回域名 (不带前导 www.) ;否则返回空字符串。String
示例
使用示例
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');┌─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 │
└─────────────────────────────────────────────────────────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────────────┘encodeURLComponent
引入版本:v22.3.0
接受一个普通字符串,并将其转换为 URL 编码 (百分号编码) 格式,其中特殊字符会替换为对应的百分号编码表示。
语法
encodeURLComponent(url)参数
url— URL。String
返回值
返回编码后的 URL。 String
示例
用法示例
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
引入版本:v22.3.0
按照表单编码规则 (RFC-1866) 对字符串进行编码,其中空格会转换为 + 号,特殊字符会进行百分比编码。
语法
encodeURLFormComponent(url)参数
url— URL。String
返回值
返回经过编码的 URL。 String
示例
使用示例
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
引入版本:v1.1.0
返回 URL 中 name 参数的值;如果不存在,则返回空字符串。
如果存在多个同名参数,则返回第一次出现的值。
该函数假定 url 参数中的该参数与 name 参数采用相同的编码方式。
语法
extractURLParameter(url, name)参数
返回值
返回名称为指定值的 URL 参数值。String
示例
用法示例
SELECT extractURLParameter('http://example.com/?param1=value1¶m2=value2', 'param1');┌─extractURLParameter('http://example.com/?param1=value1¶m2=value2', 'param1')─┐
│ value1 │
└──────────────────────────────────────────────────────────────────────────────────┘extractURLParameterNames
引入版本:v1.1.0
返回由 URL 参数名称对应的字符串组成的数组。 这些值不会被解码。
语法
extractURLParameterNames(url)参数
url— URL。String
返回值
返回一个字符串数组,其中包含与 URL 参数名称对应的名称字符串。Array(String)
示例
使用示例
SELECT extractURLParameterNames('http://example.com/?param1=value1¶m2=value2');┌─extractURLParameterNames('http://example.com/?param1=value1¶m2=value2')─┐
│ ['param1','param2'] │
└─────────────────────────────────────────────────────────────────────────────┘extractURLParameters
引入版本:v1.1.0
返回一个数组,其中包含与 URL 参数对应的 name=value 字符串。
这些值不会被解码。
语法
extractURLParameters(url)参数
url— URL。String
返回值
返回一个数组,其中包含与 URL 参数对应的 name=value 字符串。Array(String)
示例
使用示例
SELECT extractURLParameters('http://example.com/?param1=value1¶m2=value2');┌─extractURLParameters('http://example.com/?param1=value1¶m2=value2')─┐
│ ['param1=value1','param2=value2'] │
└─────────────────────────────────────────────────────────────────────────┘firstSignificantSubdomain
引入版本:v1.1.0
返回“第一个有效子域名”。
如果二级域名是“com”“net”“org”或“co”,则第一个有效子域名为二级域名。 否则为三级域名。
例如,firstSignificantSubdomain('https://news.clickhouse.com/') = 'clickhouse',firstSignificantSubdomain ('https://news.clickhouse.com.tr/') = 'clickhouse'。
“无效”二级域名的列表以及其他实现细节在未来可能会发生变化。
语法
firstSignificantSubdomain(url)参数
- 无。
返回值
示例
firstSignificantSubdomain
SELECT firstSignificantSubdomain('https://news.clickhouse.com/')┌─firstSignificantSubdomain('https://news.clickhouse.com/')─┐
│ clickhouse │
└───────────────────────────────────────────────────────────┘firstSignificantSubdomainCustom
引入版本:v21.1.0
使用自定义 TLD (顶级域名) 列表返回 URL 的第一个有效子域名。自定义 TLD 列表名称指向一个配置,用于定义哪些域名后缀应被视为顶级域。这对于非标准的 TLD 层级结构非常有用。该函数使用简化的 URL 解析算法,并假定协议及其后的所有内容都已被去掉。
语法
firstSignificantSubdomainCustom(url, tld_list_name)参数
返回值
返回第一个有效的子域名。String
示例
基本用法
SELECT firstSignificantSubdomainCustom('https://news.example.com', 'public_suffix_list')examplefirstSignificantSubdomainCustomRFC
引入版本:v22.10.0
与 firstSignificantSubdomainCustom 类似,但它使用符合 RFC 3986 的 URL 解析方式,而不是简化算法。
语法
firstSignificantSubdomainCustomRFC(url, tld_list_name)参数
返回值
返回第一个有效的子域名。String
示例
基本用法
SELECT firstSignificantSubdomainCustomRFC('https://news.example.com', 'public_suffix_list')examplefirstSignificantSubdomainRFC
首次引入于:v22.10.0
根据 RFC 1034,返回“第一个有效子域名”。
语法
firstSignificantSubdomainRFC(url)参数
- 无。
返回值
示例
fragment
引入版本:v1.1.0
返回不包含开头哈希符号的片段标识符。
语法
fragment(url)参数
url— URL。String
返回值
返回去掉开头哈希符号后的片段标识符。String
示例
使用示例
SELECT fragment('https://clickhouse.com/docs/get-started/setup/cloud#1-create-a-clickhouse-service');┌─fragment('https://clickhouse.com/docs/get-started/setup/cloud#1-create-a-clickhouse-service')─┐
│ 1-create-a-clickhouse-service │
└───────────────────────────────────────────────────────────────────────────────────────────────┘netloc
引入版本:v20.5.0
从 URL 中提取网络位置部分 (username:password@host:port) 。
语法
netloc(url)参数
url— URL。String
返回值
返回给定 URL 中的 username:password@host:port。String
示例
用法示例
SELECT netloc('http://paul@www.example.com:80/');┌─netloc('http://paul@www.example.com:80/')─┐
│ paul@www.example.com:80 │
└───────────────────────────────────────────┘path
自 v1.1.0 起引入
返回 URL 中不含查询字符串的路径。
语法
path(url)参数
url— URL。String
返回值
返回 URL 中不含查询字符串的路径部分。String
示例
使用示例
SELECT path('https://clickhouse.com/docs/reference/functions/regular-functions/url-functions?query=value');┌─path('https://clickhouse.com/docs/reference/functions/regular-functions/url-functions?query=value')─┐
│ /docs/reference/functions/regular-functions/url-functions │
└─────────────────────────────────────────────────────────────────────────────────────────────────────┘pathFull
在 v1.1.0 中引入
与 path 相同,但还包含 URL 的查询字符串和片段标识符。
语法
pathFull(url)参数
url— URL。String
返回值
返回 URL 的路径,包含查询字符串和片段标识符。String
示例
使用示例
SELECT pathFull('https://clickhouse.com/docs/reference/functions/regular-functions/url-functions?query=value#section');┌─pathFull('https://clickhouse.com/docs/reference/functions/regular-functions/url-functions?query=value#section')─┐
│ /docs/reference/functions/regular-functions/url-functions?query=value#section │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘port
首次引入版本:v20.5.0
返回 URL 的端口;如果 URL 中不包含端口,或无法解析该 URL,则返回 default_port。
语法
port(url[, default_port])参数
返回值
返回 URL 的端口;如果 URL 中不包含端口,或验证出错,则返回默认端口。UInt16
示例
用法示例
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
引入版本:v22.10.0
返回端口;如果 URL 不包含端口或无法解析,则返回 default_port。
与 port 类似,但符合 RFC 3986 规范。
语法
portRFC(url[, default_port])参数
返回值
返回端口号;如果 URL 中不包含端口,或验证出错,则返回默认端口。UInt16
示例
用法示例
SELECT port('http://user:password@example.com:8080/'), portRFC('http://user:password@example.com:8080/');┌─port('http://user:password@example.com:8080/')─┬─portRFC('http://user:password@example.com:8080/')─┐
│ 0 │ 8080 │
└────────────────────────────────────────────────┴───────────────────────────────────────────────────┘protocol
引入版本:v1.1.0
从 URL 中提取协议。
典型返回值包括:http、https、ftp、mailto、tel、magnet。
语法
protocol(url)参数
url— URL。String
返回值
返回 URL 的协议;如果无法确定,则返回空字符串。String
示例
使用示例
SELECT protocol('https://clickhouse.com/');┌─protocol('https://clickhouse.com/')─┐
│ https │
└─────────────────────────────────────┘queryString
自 v1.1.0 起引入
返回 URL 的查询字符串,不包含开头的问号、# 以及 # 之后的所有内容。
语法
queryString(url)参数
url— URL。String
返回值
返回 URL 的查询字符串,不包含开头的问号和片段标识符。String
示例
用法示例
SELECT queryString('https://clickhouse.com/docs?query=value¶m=123#section');┌─queryString('https://clickhouse.com/docs?query=value¶m=123#section')─┐
│ query=value¶m=123 │
└──────────────────────────────────────────────────────────────────────────┘queryStringAndFragment
引入版本:v1.1.0
返回 URL 的查询字符串和片段标识符。
语法
queryStringAndFragment(url)参数
url— URL。String
返回值
返回 URL 的查询字符串和片段标识符。String
示例
使用示例
SELECT queryStringAndFragment('https://clickhouse.com/docs?query=value¶m=123#section');┌─queryStringAndFragment('https://clickhouse.com/docs?query=value¶m=123#section')─┐
│ query=value¶m=123#section │
└─────────────────────────────────────────────────────────────────────────────────────┘topLevelDomain
版本引入:v1.1.0
从 URL 中提取顶级域名。
语法
topLevelDomain(url)参数
url— URL。String
返回值
如果输入字符串可以解析为 URL,则返回域名;否则返回空字符串。String
示例
用法示例
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
引入版本:v22.10.0
从 URL 中提取顶级域名。
与 topLevelDomain 类似,但遵循 RFC 3986。
语法
topLevelDomainRFC(url)参数
url— URL。String
返回值
如果输入字符串可解析为 URL,则返回域名;否则返回空字符串。 String
示例
用法示例
SELECT topLevelDomain('http://foo:foo%41bar@foo.com'), topLevelDomainRFC('http://foo:foo%41bar@foo.com');┌─topLevelDomain('http://foo:foo%41bar@foo.com')─┬─topLevelDomainRFC('http://foo:foo%41bar@foo.com')─┐
│ │ com │
└────────────────────────────────────────────────┴───────────────────────────────────────────────────┘