ST_TOLINESTRING scalar function

The ST_TOLINESTRING function takes a geometry as an input parameter and converts it to a linestring.

The specified geometry must be a linestring.

If geometry is null, the result is the null value. An empty linestring is not supported.

Read syntax diagramSkip visual syntax diagramST_TOLINESTRING(geometry)
geometry
A value of type ST_GEOMETRY or one of its subtypes that represents the geometry that is converted to a linestring.
A geometry can be converted to a linestring if it is a linestring. If the conversion cannot be performed, then an exception condition is raised.

The result of the function is ST_LINESTRING.

Example

In this example, the ST_TOLINESTRING function is used to return a linestring converted to ST_LINESTRING from the static type of ST_GEOMETRY.

CREATE TABLE sample_geometries  (id INTEGER, geometry QSYS2.ST_GEOMETRY);
CREATE TABLE sample_linestrings (id INTEGER, line QSYS2.ST_LINESTRING);

INSERT INTO sample_geometries
  VALUES (1, QSYS2.ST_LINESTRING ('linestring (0 10, 0  0, 10 0)'));

INSERT INTO sample_linestrings 
 (SELECT ID, QSYS2.ST_TOLINESTRING(geometry)
   FROM sample_geometries);
   
SELECT id, QSYS2.ST_ASTEXT(line) AS lines FROM sample_linestrings;

Results:


ID          LINES
--------    --------------------
       1    LINESTRING (0.0 10.0, 0.0 0.0, 10.0 0.0)