UrlPart

The UrlPart function extracts a specified component from a URL and returns it as text.

Syntax

UrlPart(component, url)

Function arguments:

componentThe part of the URL to be extracted. Can be one of “scheme”, “authority”, “userinfo”, “host”, “port”, “path”, “query”, or “fragment”.
urlThe 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 authority component is a combination of userinfo, host, and port.
  • 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") returns null in Snowflake, but other dialects return def.
    • Snowflake does not return the leading / for the path.
      • UrlPart("path", "https://example.com/path/to/page") returns path/to/page rather than /path/to/page.
    • Databricks and Trino don't recognize paths that start after the first colon.
    • Snowflake returns null for URLs containing an IPv6 address.

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.