ST_IsValid
What is ST_IsValid?
ST_IsValid returns a boolean indicating whether a geometry is well-formed according to the OGC Simple Features specification — no self-intersections on polygon rings, no duplicate vertices, proper nesting of holes, and so on.
1ST_IsValid(geometry geom) → boolean
2ST_IsValid(geometry geom, integer flags) → booleanPassing flags = 1 enables the "ESRI-compatible" relaxed validation that accepts self-touching rings. Invalid geometries still produce output from most PostGIS functions, but results may be undefined.
When would you use ST_IsValid?
Use ST_IsValid as a first check before running overlay operations — ST_Union, ST_Intersection, ST_Difference — which can crash or produce wrong results on invalid input. Many ingest pipelines apply ST_IsValid as a quality gate, rejecting or repairing features that fail.
It is also useful for catching issues introduced by coordinate transformations or rounding — some valid polygons become self-intersecting after aggressive ST_SnapToGrid or ST_QuantizeCoordinates.
FAQs
Why is my polygon invalid?
Common reasons: rings self-intersect (figure-8 shape), inner rings touch exterior, or rings are incorrectly wound. Use ST_IsValidReason to get a human-readable explanation.
Can I repair invalid geometry?
Yes. ST_MakeValid attempts to repair most common validity issues, returning a valid geometry that may have a different type (e.g. a self-intersecting polygon may become a MULTIPOLYGON).
Does ST_IsValid use an index?
No. Validity is checked per-geometry on the full shape. For large tables, cache the result in a column and refresh on write.
What does flags = 1 do?
Relaxes validity to allow self-touching rings that are accepted by some ESRI tools (but not by OGC). Use only when interoperating with software that emits such geometry.