Skip to main content
Version: 1.1.1

URL Functions

Introduction

URL 提取函数可从 HTTP URL(或任何符合 RFC 3986 的有效 URI)中提取组件。支持以下语法:


[protocol:][//host[:port]][path][?query][#fragment]

提取的组件不包含 URI 语法分隔符,例如“:”、“?”和“#”。

例如,请考虑以下 URI:


http://www.ics.uci.edu/pub/ietf/uri/?k1=v1#Related

scheme = http
authority = www.ics.uci.edu
path = /pub/ietf/uri/
query = k1=v1
fragment = Related

Invalid URI's

格式正确的 URI 不应包含 ASCII 空格。百分号编码的 URI 应在百分 号%后跟两位十六进制数字。所有 URL 提取函数在传递无效 URI 时都将返回 null。


# Examples of url functions with Invalid URI's.

# Invalid URI due to whitespace
SELECT url_extract_path('foo '); -- NULL (1 row)
SELECT url_extract_host('http://www.foo.com '); -- NULL (1 row)

# Invalid URI due to improper escaping of '%'
SELECT url_extract_path('https://www.ucu.edu.uy/agenda/evento/%%UCUrlCompartir%%'); -- NULL (1 row)
SELECT url_extract_host('https://www.ucu.edu.uy/agenda/evento/%%UCUrlCompartir%%'); -- NULL (1 row)

Extraction Functions

    url_extract_fragment(url) -> varchar

从“url”返回片段标识符。
    url_extract_host(url) -> varchar

从“url”返回主机。
    url_extract_parameter(url, name) -> varchar

返回“url”中第一个名为“name”的查询字符串参数的值。
参数提取将按照[RFC 18668.2.1](https://tools.ietf.org/html/rfc1866.html#section-8.2.1)
中规定的典型方式进行处理。
    url_extract_path(url) -> varchar

返回“url”的路径。
    url_extract_port(url) -> bigint

返回“url”的端口号。如果端口缺失,则返回 NULL
    url_extract_protocol(url) -> varchar

从“url”返回协议。
    url_extract_query(url) -> varchar

从“url”返回查询字符串。

Encoding Functions

    url_encode(value) -> varchar

通过编码对“value”进行转义,以便将其安全地包含在 URL 查询参数名称和值中:

* 字母数字字符不进行编码。
* 字符“.”、“-”、“*”和“_”不进行编码。
* ASCII 空格字符编码为“+”。
* 所有其他字符均转换为 UTF-8 编码,字节编码为字符串“%XX”,其中“XX”是 UTF-8 字节的大写十六进制值。
    url_decode(value) -> varchar

取消转义 URL 编码的“值”。
此函数与 `url_encode` 函数相反。