Skip to main content

Categories: String, Geospatial, Conversion

ST_GEOHASH

Returns the Geohash string for a given latitude and longitude.

Syntax​

ST_GEOHASH(latitude double, longitude double [, precision integer]) → varchar​

  • latitude: Latitude of the point in degrees.
  • longitude: Longitude of the point in degrees.
  • precision (optional): Length of the resulting Geohash string (1 to 20). Longer strings encode a more precise location. Default is 20.

Examples

ST_GEOHASH example
SELECT ST_GEOHASH (42.5049321, -5.7891234, 12)
-- ezecu3b3ptss
ST_GEOHASH example
SELECT ST_GEOHASH (-82.306100, 37.554162)
-- hc6ey8dh5quv0zpc8w2g
ST_GEOHASH example
SELECT ST_GEOHASH (-82.306100, 37.554162, 5)
-- hc6ey
ST_GEOHASH example
SELECT ST_GEOHASH (3.14, -1.34)
-- ebx1ce85zdrtde46u021
ST_GEOHASH example
SELECT ST_GEOHASH (3.14, -1.34, 5)
-- ebx1c
Encode the coordinates of Venice, Italy as a 6-character geohash
SELECT ST_GEOHASH(45.4408, 12.3155, 6)
-- u20f80
Encode the coordinates of Venice, Italy using the default precision
SELECT ST_GEOHASH(45.4408, 12.3155)
-- u20f80pzggn6km986wf5
Return NULL when an input is NULL
SELECT ST_GEOHASH(NULL, 12.3155, 6)
-- null