IPADDRESS_TRUNC

functionsupportedCore SQL functions

docs.snowflake.com ↗

IPADDRESS functions

Returns the network address of an IPADDRESS value for a given prefix length. The function keeps the leading bits of the address that the prefix length specifies and sets the remaining host bits to zero. For example, truncating 192.168.129.255 to a prefix length of 17 returns 192.168.128.0. Use this function to group addresses by subnet, to mask the host bits of addresses so that they’re less precise, and to match addresses against networks that are stored as a network address and a prefix length. See also: - IPADDRESS data type - TO_IPADDRESS - TRY_TO_IPADDRESS

Syntax

IPADDRESS_TRUNC( <ip_address> , <prefix_length> )

Parameters

NameRequiredDescription
ip_addressrequiredAn expression of type IPADDRESS.
prefix_lengthrequiredAn integer expression that specifies the number of leading bits of the address to keep: For an IPv4 address, specify a value from 0 through 32. For an IPv6 address, specify a value from 0 through 128. The prefix length doesn’t need to be a constant. For example, you can pass a column that stores a prefix length for each row.

Returns

Returns a value of type IPADDRESS with the same address family as the input. If either argument is NULL, the function returns NULL.

Usage notes