All Products
Search
Document Center

MaxCompute:NET_HOST

Last Updated:Mar 26, 2026

NET_HOST parses the hostname from a URL string.

Syntax

STRING NET_HOST(STRING <url>)

Parameters

ParameterRequiredTypeDescription
urlYesSTRINGThe URL string to parse. For best results, the string must conform to RFC 3986.

Return value

Returns a STRING value representing the hostname extracted from url.

  • If url contains a port number, the port is included in the result (for example, a.b:80).

  • Returns NULL if the input is empty or cannot be parsed.

Examples

Compare NET_HOST, NET_PUBLIC_SUFFIX, and NET_REG_DOMAIN

The following example runs NET_HOST, NET_PUBLIC_SUFFIX, and NET_REG_DOMAIN side by side across a range of URL formats, including standard URLs, IPv6 addresses, internationalized domain names, and unsupported URI schemes.

SELECT input
,description
,NET_HOST(input) AS HOST
,NET_PUBLIC_SUFFIX(input) AS SUFFIX
,NET_REG_DOMAIN(input) AS DOMAIN
FROM (
  SELECT "" AS input, "invalid input" AS description
  UNION ALL SELECT "http://abc.xyz", "standard URL"
  UNION ALL SELECT "//user:password@a.b:80/path?query",
                   "standard URL with relative scheme, port, path and query, but no public suffix"
  UNION ALL SELECT "https://[::1]:80", "standard URL with IPv6 host"
  UNION ALL SELECT "http://example.web.china", "standard URL with internationalized domain name"
  UNION ALL SELECT "    www.Example.Co.UK    ",
                   "non-standard URL with spaces, upper case letters, and without scheme"
  UNION ALL SELECT "mailto:?to=&subject=&body=", "URI rather than URL--unsupported"
);

Output:

+-----------------------------------+-------------------------------------------------------------------------------+-------------------+------------+---------------+
| input                             | description                                                                   | host              | suffix     | domain        |
+-----------------------------------+-------------------------------------------------------------------------------+-------------------+------------+---------------+
|                                   | invalid input                                                                 | NULL              | NULL       | NULL          |
| http://abc.xyz                    | standard URL                                                                  | abc.xyz           | xyz        | abc.xyz       |
| //user:password@a.b:80/path?query | standard URL with relative scheme, port, path and query, but no public suffix | a.b               | NULL       | NULL          |
| https://[::1]:80                  | standard URL with IPv6 host                                                   | [::1]             | NULL       | NULL          |
| http://example.web.china          | standard URL with internationalized domain name                               | example.web.china | china      | web.china     |
|         www.Example.Co.UK         | non-standard URL with spaces, upper case letters, and without scheme          | www.Example.Co.UK | Co.UK      | Example.Co.UK |
| mailto:?to=&subject=&body=        | URI rather than URL--unsupported                                              | mailto            | NULL       | NULL          |
+-----------------------------------+-------------------------------------------------------------------------------+-------------------+------------+---------------+

Filter rows by hostname

Use NET_HOST in a WHERE clause to keep only rows matching a specific host:

SELECT *
FROM your_table
WHERE NET_HOST(url_column) = 'abc.xyz';

Related functions

  • NET_PUBLIC_SUFFIX: parses the public suffix (such as com, org, or net) from a URL.

  • NET_REG_DOMAIN: parses the registered or registrable domain name (public suffix plus the preceding label) from a URL.

For the full list of network functions, see Network functions.