Returns a valid_detail row describing whether a geometry is valid. For invalid geometries, the row includes the reason for invalidity and the location of the invalid element.
Syntax
validDetail ST_IsValidDetail(geometry geom);
validDetail ST_IsValidDetail(geometry geom, integer flags);Parameters
| Parameter | Description |
|---|---|
geom | The geometry to validate. |
flags | A flag value that controls validation behavior. Set to 1 to treat self-intersecting rings that form holes as valid. This is the Environmental Systems Research Institute (ESRI) validation flag. |
Return value
Returns a valid_detail composite row with the following fields:
| Field | Type | Description |
|---|---|---|
valid | Boolean | Indicates whether the geometry is valid. |
reason | varchar | The reason the geometry is invalid. |
location | geometry | The location of the invalid element. |
Description
ST_IsValidDetail replaces the combined use of ST_IsValid and ST_IsValidReason by returning all validity information — the validity status, the reason, and the exact location — in a single row.
Examples
The following example checks whether a self-intersecting polygon is valid. The polygon POLYGON((0 0,0 1,1 0,1 1,0 0)) forms a bowtie shape that crosses itself at POINT(0.5 0.5).
SELECT (g).valid, (g).reason, st_astext((g).location)
FROM (
SELECT ST_IsValidDetail('POLYGON((0 0,0 1,1 0,1 1,0 0))'::geometry) AS g
) AS t;Output:
valid | reason | st_astext
-------+-------------------+----------------
f | Self-intersection | POINT(0.5 0.5)
(1 row)The valid field returns f (false), confirming the geometry is invalid. The reason field identifies the problem as a self-intersection, and the location field pinpoints where the intersection occurs.