PostGISGeometry Input

ST_LineFromText

What is ST_LineFromText?

ST_LineFromText parses a LINESTRING WKT string and returns the corresponding geometry. It raises an error if the input WKT is not a LineString.

SQL
1ST_LineFromText(text WKT)geometry
2ST_LineFromText(text WKT, integer srid)geometry

The typed constructor is stricter than ST_GeomFromText — use it when you want fail-fast behaviour on mis-typed inputs.

When would you use ST_LineFromText?

Use ST_LineFromText in ingestion pipelines where the schema guarantees LineString inputs — a misformed row should fail parsing immediately rather than become a silent error downstream. It is also a self-documenting choice in SQL, making the expected type explicit.

For inputs that may be any geometry type, stick with ST_GeomFromText.

FAQs

What happens if the WKT is a MultiLineString?

An error. Use ST_MLineFromText for MultiLineStrings or ST_GeomFromText for polymorphic inputs.

Is SRID required?

No. Without the second argument SRID is 0. Tag later with ST_SetSRID or supply explicitly.

Does it validate the line?

It checks that the WKT is well-formed and that the result is a LINESTRING. It does not check self-intersection (lines are allowed to cross).

How does it compare to ST_LineFromWKB?

ST_LineFromText parses text WKT; ST_LineFromWKB parses binary WKB. Use WKB for bulk loads where binary is more compact and faster.