Skip to main content
An IP address kept in a VARCHAR sorts alphabetically, accepts typos, and cannot answer whether an address falls inside a network. vsql_network_address adds four column types that validate their input, sort correctly, and come with the containment and netmask functions that go with them. It follows PostgreSQL’s inet, cidr, macaddr, and macaddr8 types.

Install

vsql_network_address.veb is already in the server’s lib/veb/ directory if you installed VillageSQL with the install script, the Docker image, or a release tarball. Install it into the server with one statement:
Confirm it is there:
To build it yourself, follow the build instructions in the repository.

What it adds

The types

Functions

Example

The rows come back in address order rather than alphabetical order, which is why 10.8.0.7 sorts first. Ask which hosts are on a network:
Derive the network and its broadcast address:
inet_contained_by is strict, so an address carrying the same netmask as the network is not contained by it. 192.168.1.5/32 inside 192.168.1.0/24 returns 1, while 192.168.1.5/24 inside the same network returns 0. Use inet_contained_by_or_equals when the stored rows carry the network’s own mask, as the example above does.

See also