ST_PolyFromText — Constructs a Polygon object given its Well-known text Representation
geometry ST_PolygonFromText(varchar WKT);
geometry ST_PolygonFromText(varchar WKT, integer
SRID);
Constructs a Polygon object given its Well-known text Representation. If the SRID is not provided, it defaults to -1.
Returns Null when the WKT is not a Polygon or PolygonM.
| 2D | 3D | M |
|---|---|---|
![]() | ![]() | ![]() |
| OGC SFS for SQL. 1.1 (1999) | OGC SFS for SQL. 1.1.0 (2005) | OGC SFS for SQL. 1.2.0 (2006) | SQL-MM Part 3 |
|---|---|---|---|
| 3.2.6.2 | 7.2.6.1 | - | 8.3.6 |
--Return the geometry from a WKT Polygon
SELECT ST_PolyFromText('POLYGON ((20 20 10, 50 20 15, 50 50 15, 20 50 15, 20 20 10))');
--Result PostgreSQL
\011 \001\003\001\000\000\000\005\000\000\000\000\000\000 ...
--Result H2
0920010301000000050000000000000000003440000000000000344 ...
--With SRID
SELECT ST_PolygonFromText('POLYGON ((20 20 10, 50 20 15, 50 50 15, 20 50 15, 20 20 10))',4386);
--EWKT
SELECT ST_Asewkt(ST_PolygonFromText('POLYGON ((20 20 10, 50 20 15, 50 50 15, 20 50 15, 20 20 10))'));
--Result
POLYGON ((20 20 10, 50 20 15, 50 50 15, 20 50 15, 20 20 10))