英文:
define GEOGRAPHY point variable in snowflake
问题
I tried:
point GEOGRAPHY
point := ST_MAKEPOINT(-2.6661587, 53.368992)
without success. Is this possible? To be used in SQL further down.
PS:
This:
BEGIN
LET point GEOGRAPHY := ST_MAKEPOINT(-2.6661587, 53);
RETURN point;
END;
SELECT
st_distance(:point, POLYGON) AS some_distance
FROM "bla"."di"."bla"
WHERE
1=1
ORDER BY st_distance(:point, POLYGON) ASC
throws:
Error: Bind variable :point not set. (line 7)
英文:
I tried:
point GEOGRAPHY
point := ST_MAKEPOINT(-2.6661587, 53.368992)
without success. Is this possible? To be used in SQL further down.
PS:
This:
BEGIN
LET point GEOGRAPHY := ST_MAKEPOINT(-2.6661587, 53);
RETURN point;
END;
SELECT
st_distance(:point, POLYGON) AS some_distance
FROM "bla"."di"."bla"
WHERE
1=1
ORDER BY st_distance(:point, POLYGON) ASC
throws:
Error: Bind variable :point not set. (line 7)
答案1
得分: 1
使用Snowflake脚本块:
BEGIN
LET point GEOGRAPHY := ST_MAKEPOINT(-2.6661587, 53.368992);
RETURN point;
END;
输出:
{"coordinates":[-2.666158700000000e+00,5.336899200000000e+01],"type":"Point"}
编辑:
CREATE OR REPLACE TABLE some_table
AS
SELECT ST_MAKEPOINT(-2.6661587, 54) POLYGON;
DECLARE
point GEOGRAPHY;
rs RESULTSET;
BEGIN
point := ST_MAKEPOINT(-2.6661587, 53);
rs := (EXECUTE IMMEDIATE
$$SELECT st_distance(TO_GEOGRAPHY(?), POLYGON) AS distance
FROM some_table
WHERE 1=1
ORDER BY distance ASC$$
USING (point));
RETURN TABLE(rs);
END;
输出:
DISTANCE
111,195.101177485
英文:
Using Snowflake Scripting block:
BEGIN
LET point GEOGRAPHY := ST_MAKEPOINT(-2.6661587, 53.368992);
RETURN point;
END;
Output:
{"coordinates":[-2.666158700000000e+00,5.336899200000000e+01],"type":"Point"}
EDIT:
CREATE OR REPLACE TABLE some_table
AS
SELECT ST_MAKEPOINT(-2.6661587, 54) POLYGON;
DECLARE
point GEOGRAPHY;
rs RESULTSET;
BEGIN
point := ST_MAKEPOINT(-2.6661587, 53);
rs := (EXECUTE IMMEDIATE
$$SELECT st_distance(TO_GEOGRAPHY(?), POLYGON) AS distance
FROM some_table
WHERE 1=1
ORDER BY distance ASC$$
USING (point));
RETURN TABLE(rs);
END;
Output:
DISTANCE
111,195.101177485
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论