I'm trying to query a GeoIP database with the following schema:
CREATE TABLE api_geoiprecord
(
start_ip inet PRIMARY KEY NOT NULL,
end_ip inet NOT NULL,
region VARCHAR(2),
country VARCHAR(2),
city VARCHAR(50),
postal_code VARCHAR(50),
latitude DOUBLE PRECISION,
longitude DOUBLE PRECISION,
dma_code INT,
area_code INT
);
When I run this query in psql
I get the result:
-- Test address, belongs to Yahoo!
SELECT city, country from api_geoiprecord
WHERE inet '68.180.194.242' BETWEEN start_ip AND end_ip
LIMIT 1;
city | country
-----------+---------
Sunnyvale | CA
(1 row)
When I run it in Django I get nothing:
def get_location(ip) -> None:
cur = connection.cursor()
cur.execute(
"""SELECT city, country FROM api_geoiprecord
WHERE inet %s BETWEEN start_ip AND end_ip
LIMIT 1;""",
(ip, )
)
return cur.fetchone()
Any thoughts?