Skip to main content

CUT_TO_FIRST_SIGNIFICANT_SUBDOMAIN

Description​

The CUT_TO_FIRST_SIGNIFICANT_SUBDOMAIN function extracts the effective part of a domain from a URL, including the top-level domain up to the "first significant subdomain". If the input URL is invalid, it returns an empty string.

Syntax​

CUT_TO_FIRST_SIGNIFICANT_SUBDOMAIN(<url>)

Parameters​

ParameterDescription
<url>The URL string to be processed. Type: VARCHAR

Return Value​

Returns VARCHAR type, representing the extracted domain part.

Special cases:

  • If url is NULL, returns NULL
  • If url is not a valid domain format, returns an empty string

Examples​

  1. Basic domain processing
SELECT cut_to_first_significant_subdomain('www.baidu.com');
+-----------------------------------------------------+
| cut_to_first_significant_subdomain('www.baidu.com') |
+-----------------------------------------------------+
| baidu.com |
+-----------------------------------------------------+
  1. Multi-level domain processing
SELECT cut_to_first_significant_subdomain('www.google.com.cn');
+---------------------------------------------------------+
| cut_to_first_significant_subdomain('www.google.com.cn') |
+---------------------------------------------------------+
| google.com.cn |
+---------------------------------------------------------+
  1. Invalid domain processing
SELECT cut_to_first_significant_subdomain('wwwwwwww');
+------------------------------------------------+
| cut_to_first_significant_subdomain('wwwwwwww') |
+------------------------------------------------+
| |
+------------------------------------------------+