The ST_CoordDim() function

The ST_CoordDim() function returns the coordinate dimensions of the ST_Geometry value.

For example, a point with a Z coordinate has three dimensions and a point with a Z coordinate and measures has four dimensions.

Syntax

ST_CoordDim(g ST_Geometry)

Return type

INTEGER

Example

The coorddim_test table is created with the columns geotype and g1. The geotype column stores the name of the geometry subclass stored in the g1 ST_Geometry column:
CREATE TABLE coorddim_test (geotype varchar(20),
                            g1      ST_Geometry);
The INSERT statements insert a sample subclass into the coorddim_test table:
INSERT INTO coorddim_test VALUES(
   'Point',
   ST_PointFromText('point (10.02 20.01)',1000)
);

INSERT INTO coorddim_test VALUES(
   'Point',
   ST_PointFromText('point z (10.02 20.01 3.21)',1000)
);

INSERT INTO coorddim_test VALUES(
   'LineString', 
   ST_LineFromText('linestring (10.02 20.01, 10.32 23.98, 11.92 25.64)',1000)
);

INSERT INTO coorddim_test VALUES(
   'LineString', 
   ST_LineFromText('linestring m (10.02 20.01 1.23, 10.32 23.98 4.56, 11.92
25.64 7.89)',1000)
);

INSERT INTO coorddim_test VALUES(
   'Polygon', 
   ST_PolyFromText('polygon ((10.02 20.01,11.92 35.64,25.02
34.15,19.15 33.94, 10.02 20.01))',1000)
);

INSERT INTO coorddim_test VALUES(
   'Polygon', 
   ST_PolyFromText('polygon zm ((10.02 20.01 9.87 1.23, 11.92
35.64 7.65 2.34, 25.02 34.15 6.54 3.45, 19.15 33.94 5.43 4.56,
10.02 20.01 9.87 1.23))',1000)
);
The SELECT statement lists the subclass name stored in the geotype column with the dimension of that geometry:
SELECT geotype, ST_CoordDim(g1) coord_dimension
   FROM coorddim_test;

geotype              coord_dimension 

Point                              2
Point                              3
LineString                         2
LineString                         3
Polygon                            2
Polygon                            4

6 row(s) retrieved.