Constructs a point from a Well-Known Text (WKT) string and an optional spatial reference identifier (SRID).
Syntax
geometry ST_PointFromText(text wKT);
geometry ST_PointFromText(text wKT, integer srid);Parameters
| Parameter | Type | Description |
|---|---|---|
wKT | text | A WKT string representing a point geometry, such as POINT(119 40). |
srid | integer | The SRID to assign to the returned geometry. If omitted, defaults to 0. |
Usage notes
If the WKT string does not represent a point, the function returns
NULL.If the WKT string is invalid, the function returns an error.
Coordinate order: In WKT, X represents longitude and Y represents latitude — for example,
POINT(119 40)means longitude 119, latitude 40. Swapping the order is a common mistake that produces incorrect geometry.The two overloads differ in the metadata of the returned object: the first returns a geometry with no defined spatial reference system (SRID = 0); the second embeds the specified SRID in the geometry's metadata.
When to use a different function
ST_PointFromText validates that the input represents a point before constructing it. If your input is already guaranteed to be a point WKT, use ST_GeomFromText instead — it skips this validation step and is faster.
If you are building points from longitude and latitude coordinates and care more about performance and accuracy than Open Geospatial Consortium (OGC) compliance, use ST_MakePoint or ST_Point.
Examples
Construct a point with SRID 4326 (WGS 84):
SELECT ST_AsEWKT(ST_PointFromText('POINT(119 40)', 4326));Output:
st_asewkt
-------------------------
SRID=4326;POINT(119 40)
(1 row)In this example, 119 is the longitude (X) and 40 is the latitude (Y).
Related functions
ST_GeomFromText— constructs any geometry type from a WKT string; faster thanST_PointFromTextwhen the input is a guaranteed point.ST_MakePoint— constructs a 2D, 3DZ, or 4D point from coordinates; preferred for performance-sensitive use cases.ST_Point— constructs a point from coordinates.