PostGISGeometry Accessors

GeometryType

What is GeometryType?

GeometryType is a PostGIS function that returns the OGC type of a geometry as an uppercase text string — 'POINT', 'LINESTRING', 'POLYGON', 'MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION', etc.

SQL
GeometryType(geometry g)text

Unlike ST_GeometryType, this function does not include the ST_ prefix and reports only the base type without Z/M information. It mirrors the OGC Simple Features GeometryType() method.

When would you use GeometryType?

Use GeometryType to branch query logic based on what kind of geometry each row contains — typical in tables with mixed types or after ST_CollectionExtract, when you need to decide whether to apply line-specific or polygon-specific operators:

SQL
1SELECT id, geom,
2       CASE GeometryType(geom)
3         WHEN 'POINT'      THEN ST_Buffer(geom, 10)
4         WHEN 'LINESTRING' THEN ST_Buffer(geom, 5)
5         ELSE geom
6       END AS output
7FROM mixed_features;

It is also useful as a data quality check (flagging rows whose type does not match the expected schema) and as a filter key in CTEs.

FAQs

What is the difference between GeometryType and ST_GeometryType?

GeometryType returns uppercase without the ST_ prefix (e.g. 'POINT'). ST_GeometryType returns the same base type with the prefix (e.g. 'ST_Point') and is slightly more informative for some subtypes. Use whichever suits your style — both compare equality-safely.

Does GeometryType include Z/M suffixes?

No. For a POINT ZM it still returns 'POINT'. To detect dimensionality use ST_NDims, ST_CoordDim, or ST_Zmflag.

Is GeometryType case-sensitive?

The return value is always uppercase. Compare with uppercase literals: GeometryType(g) = 'POLYGON'.

How can I filter rows by geometry type efficiently?

A plain GeometryType(geom) = 'POLYGON' filter works but is not index-accelerated. For very large mixed tables, consider partial indexes or storing a type-tag column populated by trigger.