- Categories:
String & binary functions (General)
PARSE_ URL¶
Returns an OBJECT value that consists of all the components (fragment, host, parameters, path, port, query, scheme) in a valid input URL/URI.
Syntax¶
Arguments¶
Required:
stringString to parse.
Optional:
permissiveFlag that determines how parse errors are handled:
- If set to
0, parse errors cause the function to fail. - If set to
1, parse errors result in an object with theerrorfield set to the respective error message (and no other fields set).
Default value is
0.- If set to
Returns¶
The function returns a value of type OBJECT.
If any input argument is NULL, the function returns NULL.
When an OBJECT value is returned, it contains the following key-value pairs:
| Key | Value |
|---|---|
fragment | An anchor that points to a location. |
host | The domain (address of a website or server). |
parameters | Values passed to the website or server. |
path | A resource’s location. |
port | The port (connection endpoint for a process or service). |
query | A query string passed to the website or server. |
scheme | The protocol. |
Examples¶
The following examples use the PARSE_URL function.
Parse URLs in table data¶
Create a table and insert rows:
The following query shows the results of PARSE_URL for the sample URLs:
This query shows the host for each sample URL:
Return the rows where the port is 4345:
Return the rows where the host is www.snowflake.com:
Parse invalid URLs¶
Parse an invalid URL that is missing the scheme. Set the permissive
argument to 0 to indicate that the function fails if the input
is invalid:
Parse an invalid URL, with the permissive argument set to 1 to
indicate that the function returns an OBJECT value that contains the error
message: