不支持的功能 'assignment from non-constant source expression'

Unsupported feature 'assignment from non-constant source expression'

我们在执行标准脚本时遇到以下错误:

错误: 不支持的功能 'assignment from non-constant source expression'。

脚本 set geo = (Select st_makepoint(-79.3810586,43.6562331));

所以你 SQL 运行 本身就是一个好的开始:

Select st_makepoint(-79.3810586,43.6562331);
ST_MAKEPOINT(-79.3810586,43.6562331)
{ "coordinates": [ -7.938105860000000e+01, 4.365623310000000e+01 ], "type": "Point" }

所以一个动态类型的简单块 let:

begin
    let geo := (Select st_makepoint(-79.3810586,43.6562331));
    return geo;
end;

092228 (P0000): SQL compilation error: error line 2 at position 4

variable 'GEO' cannot have its type inferred from initializer

所以提前声明类型给出:

declare
    geo GEOGRAPHY;
begin
    geo := (Select st_makepoint(-79.3810586,43.6562331));
    return geo;
end;

000603 (XX000): SQL execution internal error:

Processing aborted due to error 300010:3443530546; incident 6816246.

那不好。但这可能与它尚未在 GA 中的事实有关。

https://docs.snowflake.com/en/developer-guide/snowflake-scripting/variables.html#declaring-a-variable

The data type of the variable. This can be:

A SQL data type (except for GEOGRAPHY in this preview version).

因此,如果您打开了预览功能,以上内容可能适合您..

但是“标准程序”是指 JavaScript 程序:

create procedure f()
returns GEOGRAPHY
language javascript
as
$$
    var geo_sql = 'Select st_makepoint(-79.3810586,43.6562331)';
    
    var stmt1 = snowflake.createStatement( { sqlText: geo_sql } );

    var results1 = stmt1.execute();

    results1.next();
    
    return results1.getColumnValue(1);
$$
;

我们可以称之为

call f();
F
{ "coordinates": [ -7.938105860000000e+01, 4.365623310000000e+01 ], "type": "Point" }

这样就可以了..