pg_geohash

Handle geohash based functionality for spatial coordinates

Overview

PackageVersionCategoryLicenseLanguage
pg_geohash1.0GISMITC
IDExtensionBinLibLoadCreateTrustRelocSchema
1590pg_geohashNoYesNoYesNoYes-
Relatedpostgis h3 q3c pg_polyline postgis_topology postgis_raster postgis_sfcgal postgis_tiger_geocoder

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY1.01817161514pg_geohash-
RPMPIGSTY1.01817161514pg_geohash_$v-
DEBPIGSTY1.01817161514postgresql-$v-pg-geohash-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d13.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d13.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u22.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u22.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u24.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u24.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0

Build

You can build the RPM / DEB packages for pg_geohash using pig build:

pig build pkg pg_geohash         # build RPM / DEB packages

Install

You can install pg_geohash directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pg_geohash;          # Install for current active PG version
pig ext install -y pg_geohash -v 18  # PG 18
pig ext install -y pg_geohash -v 17  # PG 17
pig ext install -y pg_geohash -v 16  # PG 16
pig ext install -y pg_geohash -v 15  # PG 15
pig ext install -y pg_geohash -v 14  # PG 14
dnf install -y pg_geohash_18       # PG 18
dnf install -y pg_geohash_17       # PG 17
dnf install -y pg_geohash_16       # PG 16
dnf install -y pg_geohash_15       # PG 15
dnf install -y pg_geohash_14       # PG 14
apt install -y postgresql-18-pg-geohash   # PG 18
apt install -y postgresql-17-pg-geohash   # PG 17
apt install -y postgresql-16-pg-geohash   # PG 16
apt install -y postgresql-15-pg-geohash   # PG 15
apt install -y postgresql-14-pg-geohash   # PG 14

Create Extension:

CREATE EXTENSION pg_geohash;

Usage

pg_geohash: Geohash functions for PostgreSQL

C-based geohash functions for PostgreSQL (also supports HAWQ and Greenplum). Based on the libgeohash C library.

Background on geohash: Wikipedia: Geohash

Functions

Encode latitude/longitude to a geohash string with specified precision:

SELECT LAT_LON_TO_GEOHASH_WITH_LEN(latitude, longitude, 5) AS geohash;

Encode latitude/longitude to a full-precision geohash:

SELECT LAT_LON_TO_GEOHASH(latitude, longitude) AS geohash;

Decode a geohash back to latitude/longitude:

SELECT GEOHASH_TO_LAT_LON('dp3w7') AS lat_lon;

Example

Compute geohash-based aggregates using 5-character precision (~2.4km x 4.9km cells):

SELECT LAT_LON_TO_GEOHASH_WITH_LEN(latitude, longitude, 5) AS geohash,
       COUNT(*)
FROM crimes
GROUP BY 1
ORDER BY 2 DESC
LIMIT 10;
 geohash | count
---------+-------
 dp3w7   | 72404
 dp3tt   | 70713
 dp3tw   | 63642
 dp3wm   | 62332
 dp3wk   | 56467

Recover coordinates from a geohash:

SELECT location,
       GEOHASH_TO_LAT_LON(LAT_LON_TO_GEOHASH(latitude, longitude))
FROM crimes
LIMIT 5;

Last Modified 2026-03-12: add pg extension catalog (95749bf)