I'm trying to follow this example on Mapbox blog, about using 3D shapes in PostGIS.

The database-query is this:

DROP TABLE tilemill_buildings;
CREATE TABLE tilemill_buildings
CAST(size_sqm AS INT) as size_sqm,
CAST(ROUND(CAST(ST_ZMax(wkb_geometry)/2 AS NUMERIC),0) AS INT) AS z_xlarge,
CAST(ROUND(CAST(ST_ZMax(wkb_geometry)/2.5 AS NUMERIC),0) AS INT) AS z_large,
CAST(ROUND(CAST(ST_ZMax(wkb_geometry)/3 AS NUMERIC),0) AS INT) AS z_med,
CAST(ROUND(CAST(ST_ZMax(wkb_geometry)/4 AS NUMERIC),0) AS INT) AS z_small,
wkb_geometry AS wkb_geometry
FROM building_3d
ST_YMax(Box3D(wkb_geometry)) DESC;

...but I get this error:

ERROR:  function st_zmax(bytea) does not exist
LINE 5: CAST(ROUND(CAST(ST_ZMax(wkb_geometry)/2 AS NUMERIC),0) AS IN...
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

I have tried to re-install PostGIS twice. I have run the CREATE EXTENSION postgis; command.

Why am I getting this error, and how to fix it?

1 Answer 1


Reason is that your wkb_geometry is "well known binary" in bytea type of column, it should be geometry type. You can convert it to geometry using ST_GeomFromWKB(bytea) see this , if you dont want add new column then replace ST_ZMax(wkb_geometry) with ST_ZMax(ST_GeomFromWKB(wkb_geometry))


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.