Search Shortcut cmd + k | ctrl + k
maxmind

Read MaxMind databases (GeoLite, GeoIP, and more)

Maintainer(s): marselester

Compatibility Matrix

This table covers all DuckDB releases that have not reached end-of-life, including LTS releases, and shows the 2 most recent patch releases of each. Older patch releases are not listed, but the extension may be available for them as well.

Platform 1.4.4 1.4.5 1.5.5 1.5.6 2.0.0
Linux AMD64
Linux ARM64
macOS AMD64
macOS ARM64
Windows AMD64
Windows ARM64
WebAssembly

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 a record JSON 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.en
FROM read_mmdb('./GeoLite2-City.mmdb')
WHERE city.names.en IS NOT NULL
LIMIT 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') -> '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_regions scalar NULL NULL  
geoip_residential_proxy 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

name description input_type scope aliases typed_value
temp_directory Set the directory to which temporary files are written. VARCHAR GLOBAL [] post.db.tmp