Network address functions
Devart ODBC Driver for PostgreSQL supports the following network address operators and functions for working with IPv4/IPv6 addresses and MAC addresses.
These operations cover subnet comparison, bitwise manipulation, mask handling, and address formatting.
Network address operators (inet/cidr)
| Operator |
Description |
inet << inet |
Returns true if the left subnet is strictly contained within the right subnet (compares only network portions). |
inet <<= inet |
Returns true if the left subnet is contained within or equal to the right subnet. |
inet >> inet |
Returns true if the left subnet strictly contains the right subnet. |
inet >>= inet |
Returns true if the left subnet contains or equals the right subnet. |
inet && inet |
Returns true if the two subnets overlap (either contains or equals the other). |
~ inet |
Returns the bitwise NOT of the address. |
inet & inet |
Returns the bitwise AND of the two addresses. |
inet | inet → inet |
Returns the bitwise OR of the two addresses. |
inet + bigint |
Adds an integer offset to an IP address and returns the resulting address. |
bigint + inet |
Adds an integer offset to an IP address and returns the resulting address. |
inet - bigint |
Subtracts an integer offset from an IP address and returns the resulting address. |
inet - inet |
Returns the numeric (bigint) difference between two IP addresses. |
IP address functions
| Function |
Return type |
Description |
abbrev(inet) |
text |
Returns an abbreviated text representation of an inet value; omits the netmask when possible. |
abbrev(cidr) |
text |
Returns an abbreviated text representation of a cidr value; drops all-zero octets to the right of the netmask. |
broadcast(inet) |
inet |
Returns the broadcast address for the specified network. |
family(inet) |
integer |
Returns the address family: 4 for IPv4, 6 for IPv6. |
host(inet) |
text |
Returns only the IP address part, without the netmask. |
hostmask(inet) |
inet |
Returns the host mask of the network (bits set where host addresses vary). |
inet_merge(inet, inet) |
cidr |
Returns the smallest network that contains both of the given addresses. |
inet_same_family(inet, inet) |
boolean |
Returns true if both addresses belong to the same IP family (both IPv4 or both IPv6). |
masklen(inet) |
integer |
Returns the netmask length (number of significant network bits). |
netmask(inet) |
inet |
Returns the network mask as an address. |
network(inet) |
cidr |
Returns the network portion of the address (equivalent to casting to cidr). |
set_masklen(inet, int) |
inet |
Sets a new mask length for an inet value, preserving all address bits. |
set_masklen(cidr, int) |
cidr |
Sets a new mask length for a cidr value; bits to the right of the mask are zeroed. |
text(inet) |
text |
Returns the full, unabbreviated address including an explicit netmask. |
MAC address functions
| Function |
Return type |
Description |
trunc(macaddr) |
macaddr |
Sets the last three bytes of a MAC address to zero, leaving the vendor prefix. |
trunc(macaddr8) |
macaddr8 |
Sets the last five bytes of an 8-byte MAC address to zero, leaving a shorter prefix. |
macaddr8_set7bit(macaddr8) |
macaddr8 |
Sets the 7th bit to 1 to produce a modified EUI-64 address for IPv6 autoconfiguration. |