PostGISGeometry Editors

ST_Force3DZ

What is ST_Force3DZ?

ST_Force3DZ converts a geometry to XYZ, setting missing Z ordinates to zero or a user-supplied value. It is identical to ST_Force3D and exists for clarity when contrasted with ST_Force3DM.

SQL
1ST_Force3DZ(geometry geom)geometry
2ST_Force3DZ(geometry geom, float Zvalue)geometry

The output geometry carries the same XY coordinates, the same SRID, and the same type code but with a Z ordinate appended to every vertex.

When would you use ST_Force3DZ?

Use ST_Force3DZ when you need an explicit Z-only promotion and want the code to read as a clear dimensional intent — for example, in schema migrations that upgrade columns from geometry(Point, 4326) to geometry(PointZ, 4326) and need to back-fill existing rows.

It is also the preferred spelling in code paths that pair it with ST_Force3DM to produce consistent XYM or XYZ outputs depending on the chosen vertical reference.

FAQs

Is ST_Force3DZ different from ST_Force3D?

No — they are aliases producing identical results. ST_Force3D was introduced later as a shorter spelling.

Does it drop M values?

Yes. The output is XYZ only. Use ST_Force4D if you need XYZM.

What default Z is used?

Zero, unless the optional Zvalue argument is supplied (PostGIS 3.1+).

Why keep both ST_Force3DZ and ST_Force3D?

For symmetry with ST_Force3DM. When the intent is unambiguous, many teams prefer ST_Force3DZ because it reads as "force Z specifically" rather than the ambiguous 3D label.