Guide

Geocode addresses inside DuckDB

Install the extension from the DuckDB community repository, load a country file and geocode a whole table in SQL. No service to call, no keys.

From install to a geocoded table

geocode.sqlSQL
INSTALL gridpin_ext FROM community;
LOAD gridpin_ext;
SELECT gridpin_load('serbia.bin');   -- the file from: pip install gridpin-mcp && gridpin-fetch rs

SELECT id,
       hit ->> 'precision'       AS precision,
       (hit ->> 'lat')::DOUBLE  AS lat,
       (hit ->> 'lon')::DOUBLE  AS lon
FROM (SELECT id, gridpin_geocode(address)::JSON AS hit FROM orders);

SELECT gridpin_reverse(44.8176, 20.4569);   -- nearest address, with distance_m

Both functions return the standard JSON response as a string; unpack it with ->> or json_extract. Tested with DuckDB 1.5.6.

One country at a time

One file is loaded per session. To switch countries, run SELECT gridpin_reset(); as its own statement, then load the next file. Details: documentation.