PARSE_WKT([Wkt]) turns text such as POINT (106.7009 10.7769) into a point you can map. WKT puts longitude first. In SQL it is DuckDB ST_GeomFromText(Wkt), Snowflake TO_GEOGRAPHY(Wkt) or BigQuery ST_GEOGFROMTEXT(Wkt). If you parse WKT by hand, remember that the space after the type name is optional. 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
Well-Known Text, such as POINT (106.7009 10.7769), longitude first.
Returns a spatial object read from 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.
Where is each depot, read from its WKT?
Tableau
PARSE_WKT([Wkt])
SQL (DuckDB)
SELECTCASEWHEN Wkt ISNULLTHENNULLELSEjson_object('type', 'Point', 'coordinates', list_value(CAST (regexp_extract(Wkt, '(?i)POINT\s*\(\s*(\S+)\s+([^\s)]+)\s*\)', 1) AS DOUBLE), CAST (regexp_extract(Wkt, '(?i)POINT\s*\(\s*(\S+)\s+([^\s)]+)\s*\)', 2) AS DOUBLE)))
ENDAS result
FROM input
ORDERBY id
Row 2 is written POINT(105.8542 21.0285), with no space, and still parses. Hue has no WKT, so it gets null.
Wkt
Result
POINT (106.7009 10.7769)
[object Object]
POINT(105.8542 21.0285)
[object Object]
POINT (108.2022 16.0544)
[object Object]
null
✓ 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 point?
WKT allows POINT(x y) as well as POINT (x y), and Tableau reads both. A pattern that requires the space flags Hanoi's row as unreadable. Allow any whitespace, and any letter case, after the type name.
Tableau
ISNULL(PARSE_WKT([Wkt]))
Tempting SQL
SELECT Wkt ISNULLORNOTregexp_matches(Wkt, '^POINT \(') AS result
FROM input
ORDERBY id
SQL that matches
SELECT Wkt ISNULLORNOTregexp_matches(Wkt, '(?i)^\s*POINT\s*\(') AS result
FROM input
ORDERBY id
Wkt
Tableau
Tempting SQL
SQL that matches
POINT (106.7009 10.7769)
false
false
false
POINT(105.8542 21.0285)
false
true
false
POINT (108.2022 16.0544)
false
false
false
true
true
true
✓ The SQL that matches returns the Tableau result on every row; the marked cells are where the tempting SQL differs.
How do I write it in Snowflake or BigQuery?
The first example, written for each warehouse from its documentation. These are not run here; DuckDB is.
Snowflake
SELECTTO_GEOGRAPHY(Wkt) AS result
FROM input
ORDERBY id