ST_WKBToSQL function
The ST_WKBToSQL function takes a well-known binary (WKB) format of a geometry and, optionally, a spatial reference system identifier as input parameters and returns the corresponding geometry.
If the specified WKB format is null, then null is returned.
The ST_WKBToSQL function is identical to the ST_GeomFromWKB function. As well, ST_WKBToSQL(wkb) gives the same result as ST_Geometry(wkb, 4326). Using the ST_Geometry function is recommended over using ST_WKBToSQL because of its flexibility: ST_Geometry takes additional forms of input as well as the well-known binary format.
Syntax
Parameter
- wkb
- A value of type VARBINARY or BLOB(2G) that contains the well-known binary 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 use of the ST_WKBToSQL function. First, geometries are
stored in the SAMPLE_GEOMETRIES table in its GEOMETRY column. Then,
their well-known binary formats are stored in the WKB column
using the ST_AsBinary function in the UPDATE statement. Finally, the
ST_WKBToSQL function is used to return the coordinates of the geometries
in the WKB column.
CREATE TABLE sample_geometries
(id INTEGER, geometry ST_Geometry, wkb varbinary(32000) )
INSERT INTO sample_geometries (id, geometry)
VALUES (10, ST_Point ( 'point (44 14)', 0 ) ),
(11, ST_Point ( 'point (24 13)', 0 ) ),
(12, ST_Polygon ('polygon ((50 20, 50 40, 70 30, 50 20))', 0 ) )
UPDATE sample_geometries AS temp_correlated
SET wkb = ST_AsBinary(geometry)
WHERE id = temp_correlated.id
Use this SELECT statement to see the geometries in the
WKB column.
SELECT id, CAST( ST_AsText( ST_WKBToSQL(wkb, 0) ) AS VARCHAR(120) ) GEOMETRIES
FROM sample_geometries
Results:
ID GEOMETRIES
----------- -------------------------------------------------------------
10 POINT (44 14)
11 POINT (24 13)
12 POLYGON ((50 20, 70 30, 50 40, 50 20))