Cast point geometry from 2D to 3D

A minimal example on how to use SQL in PostGIS to cast table’s point geometry between Z- and/or M-enabled points.

Replace 3857 value with given table’s geometry EPSG code.

Point to Point Z

ALTER TABLE "PointTable" ALTER COLUMN "geom" type geometry (POINTZ, 3857)
USING ST_SetSRID(ST_MakePoint(ST_X("geom"), ST_Y("geom"), 0), 3857);

Point to Point M

ALTER TABLE "PointTable" ALTER COLUMN "geom" type geometry (POINTM, 3857)
USING ST_SetSRID(ST_MakePoint(ST_X("geom"), ST_Y("geom"), 0), 3857);

Point Z to Point ZM

ALTER TABLE "PointTable" ALTER COLUMN "geom" type geometry (POINTZM, 3857)
USING ST_SetSRID(ST_MakePoint(ST_X("geom"), ST_Y("geom"), ST_Z("geom"), 0), 3857);

Point M to Point ZM

ALTER TABLE "PointTable" ALTER COLUMN "geom" type geometry (POINTZM, 3857)
USING ST_SetSRID(ST_MakePoint(ST_X("geom"), ST_Y("geom"), 0, ST_M("geom")), 3857);