ST_YMax
What is ST_YMax?
ST_YMax is a PostGIS accessor that returns the maximum Y (northing / latitude) coordinate of a geometry's bounding box.
1ST_YMax(geometry geom) → float
2ST_YMax(box3d box) → floatWhen would you use ST_YMax?
Use ST_YMax for anything that needs the top edge of a geometry — partitioning data by latitude, building viewports, exporting WMS BBOX strings, validating that features lie within a hemisphere, or generating labels along the top of a region.
1SELECT id
2FROM features
3WHERE ST_YMax(geom) > 60; -- northern latitudesFAQs
Is Y interpreted as latitude?
In EPSG:4326 and other geographic CRSs, yes — Y is latitude in degrees. In projected CRSs it is a northing (metres, feet, etc.) specific to that CRS. ST_YMax returns the coordinate as-is and leaves interpretation to the caller.
What about empty geometries?
Empty geometries have no bounding box and ST_YMax returns NULL. Guard reporting SQL with COALESCE or NOT ST_IsEmpty(geom).
Is it cached?
Yes — PostGIS stores the 2D bounding box alongside each geometry, so ST_YMax is O(1) regardless of vertex count.
Can I use ST_YMax on a box3d?
Yes — ST_YMax(box3d) returns the Y component of the upper corner of a 3D box. Useful after calling ST_3DExtent or Box3D.