SELECT country_code, city_name, latitude, longitude, radius FROM geoip WHERE ? << netblock LIMIT 1
####
CREATE INDEX geoip_netblock_idx ON geoip USING GIST(netblock inet_ops);
####
Cables_DB=# SELECT country_code, city_name, latitude, longitude, radius FROM geoip WHERE '8.8.8.8' << netblock LIMIT 1;
country_code | city_name | latitude | longitude | radius
--------------+-----------+----------+-----------+--------
US | | 37.751 | -97.822 | 1000
(1 row)
Cables_DB=# EXPLAIN SELECT country_code, city_name, latitude, longitude, radius FROM geoip WHERE '8.8.8.8' << netblock LIMIT 1;
QUERY PLAN
---------------------------------------------------------------------------------------
Limit (cost=0.41..8.43 rows=1 width=35)
-> Index Scan using geoip_netblock_idx on geoip (cost=0.41..8.43 rows=1 width=35)
Index Cond: ((netblock)::inet >> '8.8.8.8'::inet)
(3 rows)