ST_GeometryType
What is ST_GeometryType?
ST_GeometryType is a PostGIS function that returns the SQL/MM-style geometry type of a geometry as text with the ST_ prefix — 'ST_Point', 'ST_LineString', 'ST_Polygon', 'ST_MultiPoint', 'ST_MultiLineString', 'ST_MultiPolygon', 'ST_GeometryCollection', and so on.
ST_GeometryType(geometry g) → textReports the base type without Z/M dimension flags. Mixed-case output, unlike GeometryType which returns uppercase without the prefix.
When would you use ST_GeometryType?
Use ST_GeometryType when you want standards-compliant type names for display or when integrating with tools that expect the ST_ prefix:
1SELECT ST_GeometryType(geom) AS type_name, COUNT(*)
2FROM features
3GROUP BY type_name
4ORDER BY 2 DESC;Useful for data audits, schema validation, and routing logic that branches on geometry kind. Also common in integration code where a downstream consumer expects 'ST_Polygon' rather than 'POLYGON'.
FAQs
What is the difference between ST_GeometryType and GeometryType?
ST_GeometryType returns mixed-case with the ST_ prefix ('ST_Polygon'). GeometryType returns uppercase without the prefix ('POLYGON'). Functionally equivalent for type detection — pick by convention.
Does ST_GeometryType distinguish Z/M dimensionality?
No. POINT and POINT Z both return 'ST_Point'. Use ST_Zmflag, ST_NDims, or ST_CoordDim for dimensionality.
Is the output case-sensitive?
Yes — it is mixed case. Compare carefully: ST_GeometryType(g) = 'ST_Point', not 'ST_POINT'.
How do I branch efficiently on geometry type in a CASE?
Avoid calling the function multiple times in complex CASE — store it in a subquery or CTE, then compare. For extreme performance on massive tables, maintain a type-tag column via trigger.