maxmind
Read MaxMind databases (GeoLite, GeoIP, and more)
Maintainer(s): marselester
Installing and Loading
INSTALL maxmind FROM community;LOAD maxmind;Example
SELECT geolite_city('./GeoLite2-City.mmdb', '1.0.64.0', '');About maxmind
Read any MaxMind database using table and scalar functions.
GeoLite and GeoIP databases get typed columns;
other MMDB files return JSON in a record VARCHAR column.
Scan all IP network blocks with read_mmdb().
Use the optional network parameter to limit the scan to a subnet,
e.g., read_mmdb(path, network='1.0.0.0/8').
Empty records are excluded by default; use include_empty=true to include them.
SELECT network, city.names.enFROM read_mmdb('./GeoLite2-City.mmdb')WHERE city.names.en IS NOT NULLLIMIT 1;┌─────────────┬───────────┐│ network │ en │├─────────────┼───────────┤│ 1.0.64.0/20 │ Hiroshima │└─────────────┴───────────┘Look up a record by IP address with typed scalar functions that return structs.
The third parameter filters which fields to decode for faster lookups (pass '' for all fields).
SELECT geolite_city('./GeoLite2-City.mmdb', '1.0.64.0', 'city').city.names.en AS en;┌───────────┐│ en │├───────────┤│ Hiroshima │└───────────┘Use mmdb_record() to look up a record from any MMDB file as JSON:
SELECT mmdb_record('./GeoLite2-City.mmdb', '1.0.64.0', 'city')::json -> 'city' -> 'names' ->> 'en' AS en;┌───────────┐│ en │├───────────┤│ Hiroshima │└───────────┘Added Functions
| function_name | function_type | description | comment | examples |
|---|---|---|---|---|
| extension_version | scalar | NULL | NULL | |
| geoip_anonymous_ip | scalar | NULL | NULL | |
| geoip_anonymous_plus | scalar | NULL | NULL | |
| geoip_city | scalar | NULL | NULL | |
| geoip_connection_type | scalar | NULL | NULL | |
| geoip_country | scalar | NULL | NULL | |
| geoip_densityincome | scalar | NULL | NULL | |
| geoip_domain | scalar | NULL | NULL | |
| geoip_enterprise | scalar | NULL | NULL | |
| geoip_ip_risk | scalar | NULL | NULL | |
| geoip_isp | scalar | NULL | NULL | |
| geoip_static_ip_score | scalar | NULL | NULL | |
| geoip_user_count | scalar | NULL | NULL | |
| geolite_asn | scalar | NULL | NULL | |
| geolite_city | scalar | NULL | NULL | |
| geolite_country | scalar | NULL | NULL | |
| mmdb_record | scalar | NULL | NULL | |
| read_mmdb | table | NULL | NULL |
Overloaded Functions
This extension does not add any function overloads.
Added Types
This extension does not add any types.
Added Settings
This extension does not add any settings.