根据文档,ST_GeomFromText
需要(text, integer)
,而不是(double precision)
。
您需要做的就是CONCAT()
它应该可以工作。
解决方案
ST_GeomFromText(CONCAT('LINESTRING(', "YourTable"."YourString", ')'), 4326);
为了您的测试
SELECT
ST_GeomFromText('LINESTRING(3.985 58.934, 4.56 61.2323, 5.4 63.234355, 3.25982 59.309)', 4326),
CONCAT('LINESTRING(', "T1"."C1", ')'),
ST_GeomFromText(CONCAT('LINESTRING(', "T1"."C1", ')'), 4326)
FROM
(
SELECT '3.985 58.934, 4.56 61.2323, 5.4 63.234355, 3.25982 59.309, 4.5632 58.32423' AS "C1"
) AS "T1";
纯娱乐
我决定将您的字符串转换为最初请求DOUBLE PRECISION
的字符串,然后再转换回字符串......最终结果与上面相同,但它需要做更多的工作。不过,这正是你所要求的。
SELECT
ST_GeomFromText(CONCAT('LINESTRING(', (SELECT STRING_AGG(ARRAY_TO_STRING("Line"."Points", ' '), ',') FROM REGEXP_MATCHES(ARRAY_TO_STRING(REGEXP_SPLIT_TO_ARRAY("T1"."C1", E', | ')::DOUBLE PRECISION[], ' '), '(\d*\.\d*) (\d*\.\d*)', 'g') AS "Line"("Points")), ')'), 4326)
FROM
(
SELECT '3.985 58.934, 4.56 61.2323, 5.4 63.234355, 3.25982 59.309, 4.5632 58.32423'::TEXT AS "C1"
) AS "T1";