PARSE_IP
functionsupportedCore SQL functionsReturns a JSON object consisting of all the components from a valid INET (Internet Protocol) or CIDR (Classless Internet Domain Routing) IPv4 or IPv6 string.
Syntax
supportedpartialnot supportednot scored
PARSE_IP(<expr>, '<type>' [, <permissive>])
Parameters
| Name | Required | Description |
|---|---|---|
expr | required | A string expression. |
type | required | A string that identifies the type of IP address. Supports either INET or CIDR; the value is case-insensitive. |
permissive | optional | Flag 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 the error field set to the respective error message (and no other fields set). Default value is 0. |
Returns
OBJECT.
Usage notes
- The function parses an IP address and returns a JSON object. The following elements are always returned: If a subnet mask is input, the results include network_prefix_length, a numeric value that identifies the length of the subnet mask. The following elements are returned for IPv4 addresses: The following elements are returned for IPv6 addresses: The snowflake$type element is reserved for internal Snowflake usage.
- family: Numeric value. 4 (IPv4) or 6 (IPv6).
- ip_type: String value. inet or cidr from the input.
- host: String value. Host address from the input expression.
- ip_fields: Array of 4 numeric fields, each a value between 0 and 4,294,967,295 (2^32 - 1), inclusive. The bit values from this array are mapped to the raw bits in the host address. IPv4 addresses: Displays only the rightmost 32 bits of the host address. IPv6 addresses: Displays each of the 32-bit fields that map to the raw 128-bit host address from left to right.
- ipv4: Numeric IP address that matches the first field in ip_fields.
- ipv4_range_start: Numeric start address of the network, displayed when a subnet mask is included in the input.
- ipv4_range_end: Numeric end address of the network, displayed when a subnet mask is included in the input.
- hex_ipv6: IP address expressed as a fully padded, fixed-size hexadecimal value.
- hex_ipv6_range_start: Fully padded fixed-size hexadecimal start address of the network, displayed when a subnet mask is included in the input.
- hex_ipv6_range_end: Fully padded fixed-size hexadecimal end address of the network, displayed when a subnet mask is included in the input.
- For IP address range calculations or subnet mask searches, query the individual JSON elements directly. See the examples, below.
- When inputting a subnet mask, Snowflake recommends storing the function output in a VARIANT column and querying against the generated elements for better performance. See the examples.