Skip to content

Converts a GEOMETRY object into a String representation. The display format of the output data is controlled by the geometry_output_format setting, which contains the following types:

ParameterDescription
GeoJSON (default)The GEOMETRY result is rendered as a JSON object in GeoJSON format.
WKTThe GEOMETRY result is rendered as a String in WKT format.
WKBThe GEOMETRY result is rendered as a Binary in WKB format.
EWKTThe GEOMETRY result is rendered as a String in EWKT format.
EWKBThe GEOMETRY result is rendered as a Binary in EWKB format.
TO_STRING(<geometry>)
ArgumentsDescription
<geometry>The argument must be an expression of type GEOMETRY.

String.

SET geometry_output_format='GeoJSON';
SELECT
TO_GEOMETRY(
ST_GEOMETRYFROMWKT(
'SRID=4326;LINESTRING(400000 6000000, 401000 6010000)'
)
) AS pipeline_geometry;
┌────────────────────────────────────────────────────────────────────────────┐
│ pipeline_geometry │
├────────────────────────────────────────────────────────────────────────────┤
│ {"type": "LineString", "coordinates": [[400000,6000000],[401000,6010000]]} │
└────────────────────────────────────────────────────────────────────────────┘
SET geometry_output_format='WKT';
SELECT
TO_GEOMETRY(
ST_GEOMETRYFROMWKT(
'SRID=4326;LINESTRING(400000 6000000, 401000 6010000)'
)
) AS pipeline_geometry;
┌───────────────────────────────────────────┐
│ pipeline_geometry │
├───────────────────────────────────────────┤
│ LINESTRING(400000 6000000,401000 6010000) │
└───────────────────────────────────────────┘
SET geometry_output_format='EWKT';
SELECT
TO_GEOMETRY(
ST_GEOMETRYFROMWKT(
'SRID=4326;LINESTRING(400000 6000000, 401000 6010000)'
)
) AS pipeline_geometry;
┌─────────────────────────────────────────────────────┐
│ pipeline_geometry │
├─────────────────────────────────────────────────────┤
│ SRID=4326;LINESTRING(400000 6000000,401000 6010000) │
└─────────────────────────────────────────────────────┘
SET geometry_output_format='WKB';
SELECT
TO_GEOMETRY(
ST_GEOMETRYFROMWKT(
'SRID=4326;LINESTRING(400000 6000000, 401000 6010000)'
)
) AS pipeline_geometry;
┌────────────────────────────────────────────────────────────────────────────────────┐
│ pipeline_geometry │
├────────────────────────────────────────────────────────────────────────────────────┤
│ 01020000000200000000000000006A18410000000060E3564100000000A07918410000000024ED5641 │
└────────────────────────────────────────────────────────────────────────────────────┘
SET geometry_output_format='EWKB';
SELECT
TO_GEOMETRY(
ST_GEOMETRYFROMWKT(
'SRID=4326;LINESTRING(400000 6000000, 401000 6010000)'
)
) AS pipeline_geometry;
┌────────────────────────────────────────────────────────────────────────────────────────────┐
│ pipeline_geometry │
├────────────────────────────────────────────────────────────────────────────────────────────┤
│ 0102000020E61000000200000000000000006A18410000000060E3564100000000A07918410000000024ED5641 │
└────────────────────────────────────────────────────────────────────────────────────────────┘