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β
Parameter | Description |
---|---|
<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β
- Basic domain processing
SELECT cut_to_first_significant_subdomain('www.baidu.com');
+-----------------------------------------------------+
| cut_to_first_significant_subdomain('www.baidu.com') |
+-----------------------------------------------------+
| baidu.com |
+-----------------------------------------------------+
- 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 |
+---------------------------------------------------------+
- Invalid domain processing
SELECT cut_to_first_significant_subdomain('wwwwwwww');
+------------------------------------------------+
| cut_to_first_significant_subdomain('wwwwwwww') |
+------------------------------------------------+
| |
+------------------------------------------------+