PARSE_WKT([Route]) turns text such as LINESTRING (106.7009 10.7769, 105.7469 10.0452) into a line through each vertex in order. Each vertex is longitude then latitude, and a line can have more than two. In SQL it is DuckDB ST_GeomFromText(Route), Snowflake TO_GEOGRAPHY(Route) or BigQuery ST_GEOGFROMTEXT(Route). The runnable SQL builds the same GeoJSON the engine returns with json_object, because this page's DuckDB has no spatial extension. With the extension loaded, the DuckDB call is shown in the FAQ.
Updated · Checked on the xmetric engine
What is the syntax?
PARSE_WKT(string)
string
LINESTRING Well-Known Text: vertices separated by commas, each written longitude then latitude.
Returns a spatial line read from LINESTRING Well-Known Text. Null when the string is null.
What does it return, and what is the SQL?
Each example runs on the same 4 sample rows twice: the Tableau formula on the xmetric engine, and the SQL in DuckDB.
What path does each route follow?
Tableau
PARSE_WKT([Route])
SQL (DuckDB)
SELECTCASEWHEN Route ISNULLTHENNULLELSEjson_object('type', 'LineString', 'coordinates', list_transform(string_split(regexp_extract(Route, '(?i)LINESTRING\s*\((.*)\)', 1), ','), p ->list_transform(regexp_split_to_array(trim(p), '\s+'), n ->CAST (n AS DOUBLE))))
ENDAS result
FROM input
ORDERBY id
Da Nang's route has three vertices; the others have two. Row 2 has no spaces after the commas and still parses.
✓ The Tableau formula and the SQL return the same 4 rows.
Where does a straight translation go wrong?
Common mistake
Why does a pattern with a space reject a valid line?
LINESTRING(x y,x y) is as valid as LINESTRING (x y, x y), and Tableau reads it. A check that requires the space after LINESTRING marks Hanoi's route as unreadable.
Tableau
ISNULL(PARSE_WKT([Route]))
Tempting SQL
SELECT Route ISNULLORNOTregexp_matches(Route, '^LINESTRING \(') AS result
FROM input
ORDERBY id
SQL that matches
SELECT Route ISNULLORNOTregexp_matches(Route, '(?i)^\s*LINESTRING\s*\(') AS result
FROM input
ORDERBY id