All Products
Search
Document Center

MaxCompute:PARSE_URL

Last Updated:Mar 25, 2026

Extracts a component from a URL string based on the specified part value.

Syntax

string parse_url(string <url>, string <part>[, string <key>])

Parameters

url

Required. STRING. The URL to parse. Returns an error if the URL is invalid or malformed.

part

Required. STRING. The URL component to extract. Not case-sensitive.

The following table maps each part value to the corresponding URL component:

part valueURL componentDescription
HOSTexample.comThe domain name or IP address
PATH/over/there/index.dtbThe path to the resource
QUERYtype=animal&name=narwhalThe value that corresponds to key when key is specified
REFnoseThe fragment identifier (the part after #)
PROTOCOLfileThe scheme (for example, http, https, file)
AUTHORITYusername:password@example.com:8042The authority section: user info, host, and port
FILEThe file component
USERINFOusername:passwordThe user credentials before the @ symbol

key

Optional. STRING. When part is QUERY, returns the value for this specific query parameter key.

Return value

Returns a STRING value. Returns NULL if url, part, or key is NULL. Returns an error if part is not one of the valid values listed above.

Examples

All examples use the same URL:

file://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose
-- Returns example.com
SELECT parse_url('file://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose', 'HOST');

-- Returns /over/there/index.dtb
SELECT parse_url('file://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose', 'PATH');

-- Returns animal (the value of the query parameter "type")
SELECT parse_url('file://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose', 'QUERY', 'type');

-- Returns nose
SELECT parse_url('file://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose', 'REF');

-- Returns file
SELECT parse_url('file://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose', 'PROTOCOL');

-- Returns username:password@example.com:8042
SELECT parse_url('file://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose', 'AUTHORITY');

-- Returns username:password
SELECT parse_url('file://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose', 'USERINFO');

Related functions

parse_url is a string function. For more information about related string functions, see String functions.