V6_SUBNETA

Calculates a subnet address in CIDR (Classless Inter-Domain Routing) format from a binary or alphanumeric IPv6 address.

Behavior Type

Immutable

Syntax

V6_SUBNETA ( expression1, expression2 )

Parameters

expression1

(VARBINARY or VARCHAR) is the string to calculate.

expression2

(INTEGER) is the size of the subnet.

Notes

The following syntax calculates a subnet address in CIDR format from a binary or varchar IPv6 address.

V6_SUBNETA masks a binary IPv6 address B so that the N leftmost bits form a subnet address, while the remaining rightmost bits are cleared. It then converts to an alphanumeric IPv6 address, appending a slash and N.

=> V6_SUBNETA(BINARY B, INT8 N) -> VARCHAR C  

The following syntax calculates a subnet address in CIDR format from an alphanumeric IPv6 address.

=> V6_SUBNETA(VARCHAR A, INT8 N) -> V6_SUBNETA(V6_ATON(A), N) -> VARCHAR C   

Examples

=> SELECT V6_SUBNETA(V6_ATON('2001:db8::8:800:200c:417a'), 28);  
  v6_subneta   
---------------
 2001:db0::/28
(1 row)

See Also