pg_geohash

pg_geohash

pg_geohash : Handle geohash based functionality for spatial coordinates

Overview

ID Extension Package Version Category License Language
1590
pg_geohash
pg_geohash
1.0
GIS
MIT
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
postgis
h3
q3c
pg_polyline
postgis_topology
postgis_raster
postgis_sfcgal
postgis_tiger_geocoder

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
1.0
18
17
16
15
14
pg_geohash -
RPM
PIGSTY
1.0
18
17
16
15
14
pg_geohash_$v -
DEB
PIGSTY
1.0
18
17
16
15
14
postgresql-$v-pg-geohash -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el8.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el9.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el9.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el10.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el10.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d12.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
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
Package Version OS ORG SIZE File URL
pg_geohash_18 1.0 el8.x86_64 pigsty 16.0 KiB pg_geohash_18-1.0-1PIGSTY.el8.x86_64.rpm
pg_geohash_18 1.0 el8.aarch64 pigsty 15.9 KiB pg_geohash_18-1.0-1PIGSTY.el8.aarch64.rpm
pg_geohash_18 1.0 el9.x86_64 pigsty 14.9 KiB pg_geohash_18-1.0-1PIGSTY.el9.x86_64.rpm
pg_geohash_18 1.0 el9.aarch64 pigsty 14.7 KiB pg_geohash_18-1.0-1PIGSTY.el9.aarch64.rpm
pg_geohash_18 1.0 el10.x86_64 pigsty 14.9 KiB pg_geohash_18-1.0-1PIGSTY.el10.x86_64.rpm
pg_geohash_18 1.0 el10.aarch64 pigsty 14.9 KiB pg_geohash_18-1.0-1PIGSTY.el10.aarch64.rpm
postgresql-18-pg-geohash 1.0 d12.x86_64 pigsty 16.4 KiB postgresql-18-pg-geohash_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-geohash 1.0 d12.aarch64 pigsty 16.3 KiB postgresql-18-pg-geohash_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-geohash 1.0 d13.x86_64 pigsty 16.5 KiB postgresql-18-pg-geohash_1.0-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-geohash 1.0 d13.aarch64 pigsty 16.2 KiB postgresql-18-pg-geohash_1.0-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-geohash 1.0 u22.x86_64 pigsty 16.2 KiB postgresql-18-pg-geohash_1.0-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-geohash 1.0 u22.aarch64 pigsty 15.8 KiB postgresql-18-pg-geohash_1.0-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-geohash 1.0 u24.x86_64 pigsty 16.3 KiB postgresql-18-pg-geohash_1.0-1PIGSTY~noble_amd64.deb
postgresql-18-pg-geohash 1.0 u24.aarch64 pigsty 16.0 KiB postgresql-18-pg-geohash_1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_geohash_17 1.0 el8.x86_64 pigsty 16.0 KiB pg_geohash_17-1.0-1PIGSTY.el8.x86_64.rpm
pg_geohash_17 1.0 el8.aarch64 pigsty 15.9 KiB pg_geohash_17-1.0-1PIGSTY.el8.aarch64.rpm
pg_geohash_17 1.0 el9.x86_64 pigsty 14.9 KiB pg_geohash_17-1.0-1PIGSTY.el9.x86_64.rpm
pg_geohash_17 1.0 el9.aarch64 pigsty 14.7 KiB pg_geohash_17-1.0-1PIGSTY.el9.aarch64.rpm
pg_geohash_17 1.0 el10.x86_64 pigsty 14.9 KiB pg_geohash_17-1.0-1PIGSTY.el10.x86_64.rpm
pg_geohash_17 1.0 el10.aarch64 pigsty 15.0 KiB pg_geohash_17-1.0-1PIGSTY.el10.aarch64.rpm
postgresql-17-pg-geohash 1.0 d12.x86_64 pigsty 16.4 KiB postgresql-17-pg-geohash_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-17-pg-geohash 1.0 d12.aarch64 pigsty 16.2 KiB postgresql-17-pg-geohash_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-17-pg-geohash 1.0 d13.x86_64 pigsty 16.5 KiB postgresql-17-pg-geohash_1.0-1PIGSTY~trixie_amd64.deb
postgresql-17-pg-geohash 1.0 d13.aarch64 pigsty 16.2 KiB postgresql-17-pg-geohash_1.0-1PIGSTY~trixie_arm64.deb
postgresql-17-pg-geohash 1.0 u22.x86_64 pigsty 16.2 KiB postgresql-17-pg-geohash_1.0-1PIGSTY~jammy_amd64.deb
postgresql-17-pg-geohash 1.0 u22.aarch64 pigsty 15.8 KiB postgresql-17-pg-geohash_1.0-1PIGSTY~jammy_arm64.deb
postgresql-17-pg-geohash 1.0 u24.x86_64 pigsty 16.3 KiB postgresql-17-pg-geohash_1.0-1PIGSTY~noble_amd64.deb
postgresql-17-pg-geohash 1.0 u24.aarch64 pigsty 16.0 KiB postgresql-17-pg-geohash_1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_geohash_16 1.0 el8.x86_64 pigsty 16.0 KiB pg_geohash_16-1.0-1PIGSTY.el8.x86_64.rpm
pg_geohash_16 1.0 el8.aarch64 pigsty 15.9 KiB pg_geohash_16-1.0-1PIGSTY.el8.aarch64.rpm
pg_geohash_16 1.0 el9.x86_64 pigsty 14.9 KiB pg_geohash_16-1.0-1PIGSTY.el9.x86_64.rpm
pg_geohash_16 1.0 el9.aarch64 pigsty 14.7 KiB pg_geohash_16-1.0-1PIGSTY.el9.aarch64.rpm
pg_geohash_16 1.0 el10.x86_64 pigsty 14.9 KiB pg_geohash_16-1.0-1PIGSTY.el10.x86_64.rpm
pg_geohash_16 1.0 el10.aarch64 pigsty 14.9 KiB pg_geohash_16-1.0-1PIGSTY.el10.aarch64.rpm
postgresql-16-pg-geohash 1.0 d12.x86_64 pigsty 16.4 KiB postgresql-16-pg-geohash_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-16-pg-geohash 1.0 d12.aarch64 pigsty 16.3 KiB postgresql-16-pg-geohash_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-16-pg-geohash 1.0 d13.x86_64 pigsty 16.5 KiB postgresql-16-pg-geohash_1.0-1PIGSTY~trixie_amd64.deb
postgresql-16-pg-geohash 1.0 d13.aarch64 pigsty 16.2 KiB postgresql-16-pg-geohash_1.0-1PIGSTY~trixie_arm64.deb
postgresql-16-pg-geohash 1.0 u22.x86_64 pigsty 16.2 KiB postgresql-16-pg-geohash_1.0-1PIGSTY~jammy_amd64.deb
postgresql-16-pg-geohash 1.0 u22.aarch64 pigsty 15.8 KiB postgresql-16-pg-geohash_1.0-1PIGSTY~jammy_arm64.deb
postgresql-16-pg-geohash 1.0 u24.x86_64 pigsty 16.3 KiB postgresql-16-pg-geohash_1.0-1PIGSTY~noble_amd64.deb
postgresql-16-pg-geohash 1.0 u24.aarch64 pigsty 16.0 KiB postgresql-16-pg-geohash_1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_geohash_15 1.0 el8.x86_64 pigsty 16.2 KiB pg_geohash_15-1.0-1PIGSTY.el8.x86_64.rpm
pg_geohash_15 1.0 el8.aarch64 pigsty 16.0 KiB pg_geohash_15-1.0-1PIGSTY.el8.aarch64.rpm
pg_geohash_15 1.0 el9.x86_64 pigsty 16.1 KiB pg_geohash_15-1.0-1PIGSTY.el9.x86_64.rpm
pg_geohash_15 1.0 el9.aarch64 pigsty 15.8 KiB pg_geohash_15-1.0-1PIGSTY.el9.aarch64.rpm
pg_geohash_15 1.0 el10.x86_64 pigsty 16.1 KiB pg_geohash_15-1.0-1PIGSTY.el10.x86_64.rpm
pg_geohash_15 1.0 el10.aarch64 pigsty 16.1 KiB pg_geohash_15-1.0-1PIGSTY.el10.aarch64.rpm
postgresql-15-pg-geohash 1.0 d12.x86_64 pigsty 16.4 KiB postgresql-15-pg-geohash_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-15-pg-geohash 1.0 d12.aarch64 pigsty 16.2 KiB postgresql-15-pg-geohash_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-15-pg-geohash 1.0 d13.x86_64 pigsty 16.5 KiB postgresql-15-pg-geohash_1.0-1PIGSTY~trixie_amd64.deb
postgresql-15-pg-geohash 1.0 d13.aarch64 pigsty 16.2 KiB postgresql-15-pg-geohash_1.0-1PIGSTY~trixie_arm64.deb
postgresql-15-pg-geohash 1.0 u22.x86_64 pigsty 16.2 KiB postgresql-15-pg-geohash_1.0-1PIGSTY~jammy_amd64.deb
postgresql-15-pg-geohash 1.0 u22.aarch64 pigsty 15.8 KiB postgresql-15-pg-geohash_1.0-1PIGSTY~jammy_arm64.deb
postgresql-15-pg-geohash 1.0 u24.x86_64 pigsty 16.3 KiB postgresql-15-pg-geohash_1.0-1PIGSTY~noble_amd64.deb
postgresql-15-pg-geohash 1.0 u24.aarch64 pigsty 16.0 KiB postgresql-15-pg-geohash_1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_geohash_14 1.0 el8.x86_64 pigsty 16.1 KiB pg_geohash_14-1.0-1PIGSTY.el8.x86_64.rpm
pg_geohash_14 1.0 el8.aarch64 pigsty 16.0 KiB pg_geohash_14-1.0-1PIGSTY.el8.aarch64.rpm
pg_geohash_14 1.0 el9.x86_64 pigsty 16.1 KiB pg_geohash_14-1.0-1PIGSTY.el9.x86_64.rpm
pg_geohash_14 1.0 el9.aarch64 pigsty 15.8 KiB pg_geohash_14-1.0-1PIGSTY.el9.aarch64.rpm
pg_geohash_14 1.0 el10.x86_64 pigsty 16.1 KiB pg_geohash_14-1.0-1PIGSTY.el10.x86_64.rpm
pg_geohash_14 1.0 el10.aarch64 pigsty 16.1 KiB pg_geohash_14-1.0-1PIGSTY.el10.aarch64.rpm
postgresql-14-pg-geohash 1.0 d12.x86_64 pigsty 16.4 KiB postgresql-14-pg-geohash_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-14-pg-geohash 1.0 d12.aarch64 pigsty 16.2 KiB postgresql-14-pg-geohash_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-14-pg-geohash 1.0 d13.x86_64 pigsty 16.5 KiB postgresql-14-pg-geohash_1.0-1PIGSTY~trixie_amd64.deb
postgresql-14-pg-geohash 1.0 d13.aarch64 pigsty 16.2 KiB postgresql-14-pg-geohash_1.0-1PIGSTY~trixie_arm64.deb
postgresql-14-pg-geohash 1.0 u22.x86_64 pigsty 16.2 KiB postgresql-14-pg-geohash_1.0-1PIGSTY~jammy_amd64.deb
postgresql-14-pg-geohash 1.0 u22.aarch64 pigsty 15.8 KiB postgresql-14-pg-geohash_1.0-1PIGSTY~jammy_arm64.deb
postgresql-14-pg-geohash 1.0 u24.x86_64 pigsty 16.3 KiB postgresql-14-pg-geohash_1.0-1PIGSTY~noble_amd64.deb
postgresql-14-pg-geohash 1.0 u24.aarch64 pigsty 16.0 KiB postgresql-14-pg-geohash_1.0-1PIGSTY~noble_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 via package name, for the active PG version

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
pig install pg_geohash -v 14;   # install for PG 14

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;
Last updated on