- Categories:
String & binary functions (General)
PARSE_ IP¶
Returns 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¶
Arguments¶
Required:
exprA string expression.
typeA string that identifies the type of IP address. Supports either
INETorCIDR; the value is case-insensitive.
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 the
errorfield set to the respective error message (and no other fields set).
Default value is 0.
Returns¶
Usage notes¶
-
The function parses an IP address and returns a JSON object.
The following elements are always returned:
familyNumeric value.
4(IPv4) or6(IPv6).ip_typeString value.
inetorcidrfrom the input.hostString value. Host address from the input expression.
ip_fieldsArray 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.
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:
ipv4Numeric IP address that matches the first field in
ip_fields.ipv4_range_startNumeric start address of the network, displayed when a subnet mask is included in the input.
ipv4_range_endNumeric end address of the network, displayed when a subnet mask is included in the input.
The following elements are returned for IPv6 addresses:
hex_ipv6IP address expressed as a fully padded, fixed-size hexadecimal value.
hex_ipv6_range_startFully padded fixed-size hexadecimal start address of the network, displayed when a subnet mask is included in the input.
hex_ipv6_range_endFully padded fixed-size hexadecimal end address of the network, displayed when a subnet mask is included in the input.
The
snowflake$typeelement is reserved for internal Snowflake usage. -
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.