This is a Postgres extension to give you ranges
of inet values.
I wrote a tutorial-style blog post about using the Postgres
inet type in ranges that explains how you might build this extension "by hand", but since a small part of it requires C, it seems nicer to have it all packaged as an extension for people.
This package installs like any Postgres extension. First say:
make && sudo make install
You will need to have
pg_config in your path,
but normally that is already the case.
You can check with
Then in the database of your choice say:
CREATE EXTENSION inetrange;
Once you've installed the extension, you can do things like this:
SELECT '188.8.131.52' <@ inetrange('184.108.40.206', '220.127.116.11', '');
SELECT '[18.104.22.168,22.214.171.124]'::inetrange && '[126.96.36.199,188.8.131.52]'::inetrange;
You can also create exclusion constraints on
CREATE TABLE geoips ( ips inetrange NOT NULL, country_code TEXT NOT NULL, latitude REAL NOT NULL, longitude REAL NOT NULL, CONSTRAINT geoips_dont_overlap EXCLUDE USING gist (ips WITH &&) );
Because the exclusion constraint auto-generates a GiST index,
you will also get fast lookups with operators like