在Snowflake中定义地理点变量。

huangapple go评论51阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年2月18日 00:30:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/75486898.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定