ST_WKTToSQL function
The ST_WKTToSQL function takes a well-known text (WKT) format of a geometry and returns the corresponding geometry.
If the specified WKT representation is null, then null is returned.
The ST_WKTToSQL function is identical to the ST_GeomFromText function. ST_WKTToSQL(wkt) gives the same result as ST_Geometry(wkt,4326). The use of the ST_Geometry function gives you more flexibility than the ST_WKTToSQL function because ST_Geometry takes additional forms of input as well as the WKT format.
Syntax
Parameter
- wkt
- A value of type VARCHAR or CLOB(2G) that contains the WKT format of the resulting geometry.
- srs_id
- A value of type INTEGER that uniquely identifies the spatial reference system. The default value for the srs_id is 4326.
Return type
ST_Geometry
Example
In the following example, the lines of results have been reformatted for readability. The spacing in your results will vary according to your online display.
This example illustrates how ST_WKTToSQL can create and insert geometries
using their WKT formats. In this example, the default
spatial reference system is applied (4326).
CREATE TABLE sample_geometries (id INTEGER, geometry ST_Geometry)
INSERT INTO sample_geometries
VALUES (10, ST_WKTToSQL( 'point (44 14)' ) ),
(11, ST_WKTToSQL ( 'point (24 13)' ) ),
(12, ST_WKTToSQL ('polygon ((50 20, 50 40, 70 30, 50 20))' ) )
This
SELECT statement returns the geometries that have been inserted.
SELECT id, CAST( ST_AsText(geometry) AS VARCHAR(120) ) GEOMETRIES
FROM sample_geometries
Results:
ID GEOMETRIES
----------- --------------------------------------------------------------
10 POINT (44.000000000 14.000000000)
11 POINT (24.000000000 13.000000000)
12 POLYGON ((50.000000000 20.000000000, 70.000000000 30.000000000,
50.000000000 40.000000000, 50.000000000 20.000000000))
