abbrev
PG 7.4+→ textReturns an abbreviated display text for the address, removing the prefix length if it's the default (/32 for IPv4, /128 for IPv6).
Signatures
abbrev ( inet ) → textabbrev ( cidr ) → textParameters
| Parameter | Type | Description |
|---|---|---|
| address | inet or cidr | Network address to abbreviate |
Examples
SELECT abbrev('192.168.1.1/32'::inet);192.168.1.1SELECT abbrev('10.0.0.0/8'::cidr);10/8SELECT abbrev('::1/128'::inet);::1SELECT abbrev(ip_address) AS display_ip FROM audit_log ORDER BY logged_at DESC LIMIT 10;Clean IP strings without redundant /32 or /128 suffixes`host()` always strips the prefix entirely, producing a bare IP string. For network addresses like `10.0.0.0/8` this throws away the prefix, leaving just `10.0.0.0` — which loses the subnet context. `abbrev()` keeps the prefix for non-default lengths and only drops it when it is trivial (/32, /128).
✓ Instead: Prefer `abbrev(col)` for display output. Reserve `host(col)` for cases where you specifically need a bare IP string with no prefix information, such as DNS lookups or legacy text comparisons.
`abbrev` is the cleanest way to display network addresses for users — it removes the /32 suffix for single hosts and abbreviates CIDR notation (e.g., 10/8 instead of 10.0.0.0/8).
SELECT abbrev(ip_address) AS ip FROM users;Clean IP display without /32 suffix