Network Functions
PostgreSQL includes many functions that are network oriented. Primarily, these are useful for performing calculations and transformations of IP-related data. The following sections discuss the included network functions in PostgreSQL.
ABBREV
Description
The ABBREV function returns an abbreviated text format for a supplied inet or cidr value.
Input
ABBREV(inet | cidr)
Example
ABBREV('192.168.0.0/24') "192.168/24"
BROADCAST
Description
The BROADCAST function returns the broadcast address of the supplied inet or cidr value.
Input
BROADCAST(inet | cidr)
Example
BROADCAST('192.168.0.1/24') '192.168.0.255/24'
HOST
Description
The HOST function extracts the host address for the supplied inet or cidr value.
Input
HOST(inet | cidr)
Example
HOST('192.168.0.101/24') '192.168.0.101'
MASKLEN
Description
The MASKLEN function extracts the netmask length for the supplied inet or cidr value.
Input
MASKLEN(inet | cidr)
Example
MASKLEN('192.168.0.1/24') 24
NETMASK
Description
The NETMASK function calculates the netmask for the supplied inet or cidr value.
Input
NETMASK(inet | cidr)
Example
NETMASK('192.168.0.1/24') '255.255.255.0'
NETWORK
Description
The NETWORK function extracts the network from a supplied inet or cidr value.
Input
NETWORK(inet | cidr)
Example
NETWORK('192.168.0.155/24') '192.168.1.0/24'
TEXT
Description
The TEXT function returns the IP and netmask length as a text value.
Input
TEXT(inet | cidr)
Example
TEXT(CIDR '192.168.0.1/24') "192.168.0.1/24"
TRUNC
Description
The TRUNC function sets the last 3 bytes to zero for the supplied macaddr value.
Input
TRUNC(macaddr)
Example
TRUNC(macaddr '33:33:33:33:33:aa') '33:33:33:00:00:00'
Notes
This function is useful for associating a supplied MAC address with a manufacturer. See the directory $SOURCE/contrib/mac (SOURCE is the location of the PostgreSQL source code) for more information.
|