Skip to content

pg_geohash

Handle geohash based functionality for spatial coordinates

pg_geohash · Handle geohash based functionality for spatial coordinates

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
1590pg_geohashpg_geohash1.0GISMITC
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-rNoYesNoYesyesno

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY1.019 18 17 16 15pg_geohash-
RPMPIGSTY1.019 18 17 16 15pg_geohash_$v-
DEBPIGSTY1.019 18 17 16 15postgresql-$v-pg-geohash-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el8.aarch64N/APIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el9.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el9.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el10.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el10.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
d12.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
d12.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
d13.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
d13.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u22.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u22.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u24.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u24.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u26.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u26.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
PackageVersionOSORGSIZEFile URL
pg_geohash_191.0el9.x86_64pigsty26.2 KiBpg_geohash_19-1.0-5PGSTY.el9.x86_64.rpm
pg_geohash_191.0el9.aarch64pigsty25.8 KiBpg_geohash_19-1.0-5PGSTY.el9.aarch64.rpm
pg_geohash_191.0el10.x86_64pigsty26.3 KiBpg_geohash_19-1.0-5PGSTY.el10.x86_64.rpm
pg_geohash_191.0el10.aarch64pigsty26.0 KiBpg_geohash_19-1.0-5PGSTY.el10.aarch64.rpm
postgresql-19-pg-geohash1.0d12.x86_64pigsty18.3 KiBpostgresql-19-pg-geohash_1.0-4PGSTY~bookworm_amd64.deb
postgresql-19-pg-geohash1.0d12.aarch64pigsty18.1 KiBpostgresql-19-pg-geohash_1.0-4PGSTY~bookworm_arm64.deb
postgresql-19-pg-geohash1.0d13.x86_64pigsty18.4 KiBpostgresql-19-pg-geohash_1.0-4PGSTY~trixie_amd64.deb
postgresql-19-pg-geohash1.0d13.aarch64pigsty18.1 KiBpostgresql-19-pg-geohash_1.0-4PGSTY~trixie_arm64.deb
postgresql-19-pg-geohash1.0u22.x86_64pigsty18.4 KiBpostgresql-19-pg-geohash_1.0-4PGSTY~jammy_amd64.deb
postgresql-19-pg-geohash1.0u22.aarch64pigsty18.0 KiBpostgresql-19-pg-geohash_1.0-4PGSTY~jammy_arm64.deb
postgresql-19-pg-geohash1.0u24.x86_64pigsty18.5 KiBpostgresql-19-pg-geohash_1.0-4PGSTY~noble_amd64.deb
postgresql-19-pg-geohash1.0u24.aarch64pigsty18.2 KiBpostgresql-19-pg-geohash_1.0-4PGSTY~noble_arm64.deb
postgresql-19-pg-geohash1.0u26.x86_64pigsty18.5 KiBpostgresql-19-pg-geohash_1.0-4PGSTY~resolute_amd64.deb
postgresql-19-pg-geohash1.0u26.aarch64pigsty18.3 KiBpostgresql-19-pg-geohash_1.0-4PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_geohash_181.0el8.x86_64pigsty26.8 KiBpg_geohash_18-1.0-5PGSTY.el8.x86_64.rpm
pg_geohash_181.0el8.aarch64pigsty26.4 KiBpg_geohash_18-1.0-5PGSTY.el8.aarch64.rpm
pg_geohash_181.0el9.x86_64pigsty26.1 KiBpg_geohash_18-1.0-5PGSTY.el9.x86_64.rpm
pg_geohash_181.0el9.aarch64pigsty25.8 KiBpg_geohash_18-1.0-5PGSTY.el9.aarch64.rpm
pg_geohash_181.0el10.x86_64pigsty26.2 KiBpg_geohash_18-1.0-5PGSTY.el10.x86_64.rpm
pg_geohash_181.0el10.aarch64pigsty25.9 KiBpg_geohash_18-1.0-5PGSTY.el10.aarch64.rpm
postgresql-18-pg-geohash1.0d12.x86_64pigsty18.3 KiBpostgresql-18-pg-geohash_1.0-4PGSTY~bookworm_amd64.deb
postgresql-18-pg-geohash1.0d12.aarch64pigsty18.1 KiBpostgresql-18-pg-geohash_1.0-4PGSTY~bookworm_arm64.deb
postgresql-18-pg-geohash1.0d13.x86_64pigsty18.4 KiBpostgresql-18-pg-geohash_1.0-4PGSTY~trixie_amd64.deb
postgresql-18-pg-geohash1.0d13.aarch64pigsty18.1 KiBpostgresql-18-pg-geohash_1.0-4PGSTY~trixie_arm64.deb
postgresql-18-pg-geohash1.0u22.x86_64pigsty18.4 KiBpostgresql-18-pg-geohash_1.0-4PGSTY~jammy_amd64.deb
postgresql-18-pg-geohash1.0u22.aarch64pigsty18.0 KiBpostgresql-18-pg-geohash_1.0-4PGSTY~jammy_arm64.deb
postgresql-18-pg-geohash1.0u24.x86_64pigsty18.4 KiBpostgresql-18-pg-geohash_1.0-4PGSTY~noble_amd64.deb
postgresql-18-pg-geohash1.0u24.aarch64pigsty18.2 KiBpostgresql-18-pg-geohash_1.0-4PGSTY~noble_arm64.deb
postgresql-18-pg-geohash1.0u26.x86_64pigsty18.4 KiBpostgresql-18-pg-geohash_1.0-4PGSTY~resolute_amd64.deb
postgresql-18-pg-geohash1.0u26.aarch64pigsty18.3 KiBpostgresql-18-pg-geohash_1.0-4PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_geohash_171.0el8.x86_64pigsty26.8 KiBpg_geohash_17-1.0-5PGSTY.el8.x86_64.rpm
pg_geohash_171.0el8.aarch64pigsty26.4 KiBpg_geohash_17-1.0-5PGSTY.el8.aarch64.rpm
pg_geohash_171.0el9.x86_64pigsty26.1 KiBpg_geohash_17-1.0-5PGSTY.el9.x86_64.rpm
pg_geohash_171.0el9.aarch64pigsty25.8 KiBpg_geohash_17-1.0-5PGSTY.el9.aarch64.rpm
pg_geohash_171.0el10.x86_64pigsty26.2 KiBpg_geohash_17-1.0-5PGSTY.el10.x86_64.rpm
pg_geohash_171.0el10.aarch64pigsty25.9 KiBpg_geohash_17-1.0-5PGSTY.el10.aarch64.rpm
postgresql-17-pg-geohash1.0d12.x86_64pigsty18.3 KiBpostgresql-17-pg-geohash_1.0-4PGSTY~bookworm_amd64.deb
postgresql-17-pg-geohash1.0d12.aarch64pigsty18.1 KiBpostgresql-17-pg-geohash_1.0-4PGSTY~bookworm_arm64.deb
postgresql-17-pg-geohash1.0d13.x86_64pigsty18.3 KiBpostgresql-17-pg-geohash_1.0-4PGSTY~trixie_amd64.deb
postgresql-17-pg-geohash1.0d13.aarch64pigsty18.1 KiBpostgresql-17-pg-geohash_1.0-4PGSTY~trixie_arm64.deb
postgresql-17-pg-geohash1.0u22.x86_64pigsty18.8 KiBpostgresql-17-pg-geohash_1.0-4PGSTY~jammy_amd64.deb
postgresql-17-pg-geohash1.0u22.aarch64pigsty18.4 KiBpostgresql-17-pg-geohash_1.0-4PGSTY~jammy_arm64.deb
postgresql-17-pg-geohash1.0u24.x86_64pigsty18.4 KiBpostgresql-17-pg-geohash_1.0-4PGSTY~noble_amd64.deb
postgresql-17-pg-geohash1.0u24.aarch64pigsty18.1 KiBpostgresql-17-pg-geohash_1.0-4PGSTY~noble_arm64.deb
postgresql-17-pg-geohash1.0u26.x86_64pigsty18.4 KiBpostgresql-17-pg-geohash_1.0-4PGSTY~resolute_amd64.deb
postgresql-17-pg-geohash1.0u26.aarch64pigsty18.2 KiBpostgresql-17-pg-geohash_1.0-4PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_geohash_161.0el8.x86_64pigsty26.8 KiBpg_geohash_16-1.0-5PGSTY.el8.x86_64.rpm
pg_geohash_161.0el8.aarch64pigsty26.4 KiBpg_geohash_16-1.0-5PGSTY.el8.aarch64.rpm
pg_geohash_161.0el9.x86_64pigsty26.1 KiBpg_geohash_16-1.0-5PGSTY.el9.x86_64.rpm
pg_geohash_161.0el9.aarch64pigsty25.7 KiBpg_geohash_16-1.0-5PGSTY.el9.aarch64.rpm
pg_geohash_161.0el10.x86_64pigsty26.2 KiBpg_geohash_16-1.0-5PGSTY.el10.x86_64.rpm
pg_geohash_161.0el10.aarch64pigsty25.9 KiBpg_geohash_16-1.0-5PGSTY.el10.aarch64.rpm
postgresql-16-pg-geohash1.0d12.x86_64pigsty18.3 KiBpostgresql-16-pg-geohash_1.0-4PGSTY~bookworm_amd64.deb
postgresql-16-pg-geohash1.0d12.aarch64pigsty18.1 KiBpostgresql-16-pg-geohash_1.0-4PGSTY~bookworm_arm64.deb
postgresql-16-pg-geohash1.0d13.x86_64pigsty18.3 KiBpostgresql-16-pg-geohash_1.0-4PGSTY~trixie_amd64.deb
postgresql-16-pg-geohash1.0d13.aarch64pigsty18.1 KiBpostgresql-16-pg-geohash_1.0-4PGSTY~trixie_arm64.deb
postgresql-16-pg-geohash1.0u22.x86_64pigsty18.8 KiBpostgresql-16-pg-geohash_1.0-4PGSTY~jammy_amd64.deb
postgresql-16-pg-geohash1.0u22.aarch64pigsty18.4 KiBpostgresql-16-pg-geohash_1.0-4PGSTY~jammy_arm64.deb
postgresql-16-pg-geohash1.0u24.x86_64pigsty18.4 KiBpostgresql-16-pg-geohash_1.0-4PGSTY~noble_amd64.deb
postgresql-16-pg-geohash1.0u24.aarch64pigsty18.2 KiBpostgresql-16-pg-geohash_1.0-4PGSTY~noble_arm64.deb
postgresql-16-pg-geohash1.0u26.x86_64pigsty18.4 KiBpostgresql-16-pg-geohash_1.0-4PGSTY~resolute_amd64.deb
postgresql-16-pg-geohash1.0u26.aarch64pigsty18.3 KiBpostgresql-16-pg-geohash_1.0-4PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_geohash_151.0el8.x86_64pigsty26.9 KiBpg_geohash_15-1.0-5PGSTY.el8.x86_64.rpm
pg_geohash_151.0el8.aarch64pigsty26.5 KiBpg_geohash_15-1.0-5PGSTY.el8.aarch64.rpm
pg_geohash_151.0el9.x86_64pigsty27.1 KiBpg_geohash_15-1.0-5PGSTY.el9.x86_64.rpm
pg_geohash_151.0el9.aarch64pigsty26.8 KiBpg_geohash_15-1.0-5PGSTY.el9.aarch64.rpm
pg_geohash_151.0el10.x86_64pigsty27.4 KiBpg_geohash_15-1.0-5PGSTY.el10.x86_64.rpm
pg_geohash_151.0el10.aarch64pigsty27.0 KiBpg_geohash_15-1.0-5PGSTY.el10.aarch64.rpm
postgresql-15-pg-geohash1.0d12.x86_64pigsty18.4 KiBpostgresql-15-pg-geohash_1.0-4PGSTY~bookworm_amd64.deb
postgresql-15-pg-geohash1.0d12.aarch64pigsty18.2 KiBpostgresql-15-pg-geohash_1.0-4PGSTY~bookworm_arm64.deb
postgresql-15-pg-geohash1.0d13.x86_64pigsty18.5 KiBpostgresql-15-pg-geohash_1.0-4PGSTY~trixie_amd64.deb
postgresql-15-pg-geohash1.0d13.aarch64pigsty18.3 KiBpostgresql-15-pg-geohash_1.0-4PGSTY~trixie_arm64.deb
postgresql-15-pg-geohash1.0u22.x86_64pigsty19.7 KiBpostgresql-15-pg-geohash_1.0-4PGSTY~jammy_amd64.deb
postgresql-15-pg-geohash1.0u22.aarch64pigsty19.3 KiBpostgresql-15-pg-geohash_1.0-4PGSTY~jammy_arm64.deb
postgresql-15-pg-geohash1.0u24.x86_64pigsty19.4 KiBpostgresql-15-pg-geohash_1.0-4PGSTY~noble_amd64.deb
postgresql-15-pg-geohash1.0u24.aarch64pigsty19.1 KiBpostgresql-15-pg-geohash_1.0-4PGSTY~noble_arm64.deb
postgresql-15-pg-geohash1.0u26.x86_64pigsty19.4 KiBpostgresql-15-pg-geohash_1.0-4PGSTY~resolute_amd64.deb
postgresql-15-pg-geohash1.0u26.aarch64pigsty19.2 KiBpostgresql-15-pg-geohash_1.0-4PGSTY~resolute_arm64.deb

Source

pig build pkg pg_geohash;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

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

Install this extension with pig:

pig install pg_geohash;		# install by package name

pig install pg_geohash -v 19;   # install for PG 19
pig install pg_geohash -v 18;   # install for PG 18
pig install pg_geohash -v 17;   # install for PG 17
pig install pg_geohash -v 16;   # install for PG 16
pig install pg_geohash -v 15;   # install for PG 15

Create this extension with:

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;

Table reader