Parse a Well-Known Text (WKT) string into an internal geometry value.
ST_GEOM_FROM_TEXT(wkt)
## Overview Parses a Well-Known Text (WKT) string and returns a GEOMETRY value that can be used with any other ST_ function. WKT is the portable text format defined by the OGC Simple Features specification and is the standard interchange format for passing geometries through SQL, REST APIs, CSV files, and log lines. ST_GEOM_FROM_TEXT is the inverse of ST_AS_TEXT. A geometry parsed from WKT, then re-serialized, then parsed again, produces an equivalent geometry within double-precision rounding. ## When to use ST_GEOM_FROM_TEXT vs. alternatives - **ST_GEOM_FROM_TEXT** (this function): construct any geometry type from a WKT string literal or column. - **ST_MAKE_POINT**: faster path when you only need a POINT built from two numeric coordinates; avoids the parser entirely. - **Binary (WKB) constructors**: not covered here. Use only when ingesting binary geometry payloads from external tools. ## Behavior - Accepts the OGC WKT grammar for POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, and GEOMETRYCOLLECTION. - Coordinate order inside WKT is (x y), which corresponds to (longitude latitude) for geographic data. The function does not reorder coordinates. - Polygon rings must be explicitly closed: the first and last vertex of each ring must be identical. Unclosed rings are rejected or produce an invalid geometry. - Whitespace between tokens is flexible; case of the type keyword is not significant. - Returns NULL if the input string is NULL. - Malformed WKT produces an error or NULL depending on the runtime's strictness setting. Never assume an invalid string silently becomes NULL. - Does not attach an SRID to the resulting geometry. SRID must be tracked in a sibling column if it matters to the workload. ## Input format - Coordinate values are parsed as double precision. Very long decimal expansions are truncated silently. - Empty geometries are represented as 'POINT EMPTY', 'POLYGON EMPTY', etc., and parse to empty GEOMETRY values. - POLYGON exterior rings may be followed by zero or more interior rings (holes), each in its own parenthesized list. - GEOMETRYCOLLECTION members may be heterogeneous; the resulting geometry exposes the collection to downstream functions. ## Compatibility - Follows the OGC Simple Features specification for WKT. - Output is compatible with other SQL engines and GIS libraries that consume standard WKT.
| Name | Type | Description |
|---|---|---|
wkt | Specifies the Well-Known Text string to parse. Must conform to the OGC Simple Features grammar, for example 'POINT(x y)', 'LINESTRING(x1 y1, x2 y2, ...)', or 'POLYGON((x1 y1, ..., x1 y1))'. Coordinate order is (x y), which corresponds to (longitude latitude) for geographic data. |
-- WKT coordinates are (longitude latitude) for geographic data.
SELECT ST_GEOM_FROM_TEXT('POINT(-74.0060 40.7128)') AS geom;
-- The first and last vertex of each ring must be identical.
SELECT ST_GEOM_FROM_TEXT('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))') AS geom;
-- Ordered list of waypoints in (lng lat) order.
SELECT ST_GEOM_FROM_TEXT('LINESTRING(-0.1278 51.5074, 2.3522 48.8566, 13.4050 52.5200)') AS geom;
-- Multiple disjoint polygons in a single geometry value.
SELECT ST_GEOM_FROM_TEXT(
'MULTIPOLYGON(((0 0, 2 0, 2 2, 0 2, 0 0)), ((5 5, 7 5, 7 7, 5 7, 5 5)))'
) AS geom;
-- Parsing and re-serializing yields an equivalent geometry within floating-point tolerance.
SELECT ST_AS_TEXT(ST_GEOM_FROM_TEXT('POINT(139.6503 35.6762)')) AS wkt;
-- Combine ST_GEOM_FROM_TEXT with ST_CONTAINS and ST_MAKE_POINT.
SELECT ST_CONTAINS(
ST_GEOM_FROM_TEXT('POLYGON((-1 50, 1 50, 1 52, -1 52, -1 50))'),
ST_MAKE_POINT(-0.1278, 51.5074)
) AS in_box;