host
PG 7.4+→ textReturns the host address from an inet value as text, without the subnet mask.
Signature
host ( inet ) → textParameters
| Parameter | Type | Description |
|---|---|---|
| address | inet or cidr | Network address |
Examples
SELECT host('192.168.1.1/24'::inet);192.168.1.1SELECT host('::1/128'::inet);::1SELECT host(client_ip) AS plain_ip FROM connections WHERE host(client_ip) = '10.0.0.1';10.0.0.1SELECT host(ip_address), masklen(ip_address) FROM servers ORDER BY ip_address;host and prefix length for each server`host()` always strips the prefix and returns a bare IP string, but for user-facing display `abbrev()` is more informative — it drops the /32 suffix for single hosts while keeping the prefix for networks. Defaulting to `host()` everywhere discards CIDR context that security reviewers often need.
✓ Instead: Use `abbrev(ip_col)` for display: it renders single-host /32 addresses as plain IPs and keeps meaningful prefixes on network addresses, so the output is compact without throwing away subnet information.
`host(inet_col)` extracts the IP string without the prefix length. Use this when you need to compare or display the IP address as a plain string.
SELECT host(ip_address) AS ip, masklen(ip_address) AS prefix FROM clients;IP and prefix length as separate values