A função NET_PUBLIC_SUFFIX extrai o sufixo público, como com, org ou net, de uma string de URL.
Observações
Os sufixos públicos são domínios da ICANN registrados em publicsuffix.org. Os dados de sufixos públicos nesse site também incluem domínios privados, mas esta função os ignora.
Sintaxe
STRING NET_PUBLIC_SUFFIX(STRING <url>)
Parâmetros
url: Obrigatório. String de URL a analisar. O parâmetro deve ser do tipo STRING.
Para obter melhores resultados, a string de URL deve seguir o formato definido na RFC 3986.
Valor de retorno
Retorna um valor do tipo STRING. A função retorna NULL nas seguintes condições:
Não é possível extrair o nome do host da string de URL.
O nome do host extraído contém pontos consecutivos fora do início ou fim.
O nome do host extraído não contém sufixo público.
Os dados de sufixos públicos podem mudar ao longo do tempo. Portanto, uma entrada que retorna NULL agora pode retornar um valor diferente de NULL no futuro.
Funções de análise relacionadas
Use as funções abaixo para analisar outras partes da URL além do sufixo público:
NET_HOST: Extrai o nome do host de uma URL.
NET_REG_DOMAIN: Extrai o domínio registrado ou registrável de uma URL (sufixo público mais o rótulo precedente).
Exemplos
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"
);
+-----------------------------------+-------------------------------------------------------------------------------+-------------------+------------+---------------+
| 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 |
+-----------------------------------+-------------------------------------------------------------------------------+-------------------+------------+---------------+
Funções relacionadas
NET_PUBLIC_SUFFIX é uma função de rede. Para mais informações sobre funções de rede, consulte Network functions.