UrlPart
The UrlPart function extracts a specified component from a URL and returns it as text.
Syntax
UrlPart(component, url)
Function arguments:
| component | The part of the URL to be extracted. Can be one of “scheme”, “authority”, “userinfo”, “host”, “port”, “path”, “query”, or “fragment”. |
| url | The URL to extract the component from. If url is null the function returns null. |
Notes
- For the purposes of the UrlPart function, a standard URL is constructed like the following:
scheme://userinfo@host:port/path?query#fragment.- The
authoritycomponent is a combination ofuserinfo,host, andport.
- The
- Though all platforms are supported, Sigma uses native URL parsing for all SQL dialects where possible. As a result, there are behavior differences between platforms, including:
- Results for invalid URLs vary by component and dialect.
UrlPart("query", "abc?def")returnsnullin Snowflake, but other dialects returndef.
- Snowflake does not return the leading
/for the path.UrlPart("path", "https://example.com/path/to/page")returnspath/to/pagerather than/path/to/page.
- Databricks and Trino don't recognize paths that start after the first colon.
- Typically, in the
mailto:URI scheme, such asmailto:[email protected],[email protected]would be the path. ButUrlPart("path", mailto:[email protected])returnsnullin Databricks and an empty string in Trino.
- Typically, in the
- Snowflake returns
nullfor URLs containing an IPv6 address.
- Results for invalid URLs vary by component and dialect.
Examples
UrlPart("scheme", "https://www.example.com")
Extracts the scheme from https://www.example.com and returns https.
UrlPart("authority", "https://[email protected]:1234/path/to/page")
Extracts the authority from https://[email protected]:1234/path/to/page and returns [email protected]:1234.
UrlPart("query", "https://www.example.com/path/to/page?query=string#fragment")
Extracts the query from https://www.example.com/path/to/page?query=string#fragment and returns query=string.
UrlPart("fragment", "https://www.example.com/path/to/page?query=string#sub-heading")
Extracts the fragment from https://www.example.com/path/to/page?query=string#sub-heading and returns sub-heading.
Updated about 1 month ago
