存储过程抛出 "Missing Column Specification"

Stored procedure throwing "Missing Column Specification"

我正在使用 Javascript 创建 Snowflake 存储过程。 我收到程序抛出的 SQL 异常,提示“缺少列规范”。

堆栈跟踪指向这部分:

var cmd_outputCreation = `CREATE OR REPLACE TABLE ${TBL_OUTPUT} AS(
                                    SELECT A.*, B.RESULT[0], B.RESULT[1]
                                    FROM(
                                      SELECT ${API_FUNCTION}(joined.*) AS result
                                      FROM (
                                          SELECT ${c_id}, ${c_location_name}, 
                                          ${c_street_address}, ${c_city}, ${c_region}, 
                                          ${c_postal_code}, ${c_latitude}, ${c_longitude},
                                          ${c_country_code}
                                          FROM ${TBL_INPUT} 
                                      ) AS joined
                                    ) AS B
                                    INNER JOIN ${TBL_INPUT} AS A
                                    ON A.RECID = B.RESULT[0]
                                  )`;
var stmt_outputCreation = snowflake.createStatement( {sqlText: cmd_outputCreation} );
var result_outputCreation = stmt_outputCreation.execute();

但是,我在这里看不到任何错误。如果我在没有 SP 的情况下使用它,查询本身将在 SQL 上运行(显然用实际 SQL Tables/columns)

替换变量名称

而且我知道“Missing Column Specification”的意思是“A column has no name”,但事实似乎并非如此。我在这里错过了什么?

您需要为 B.RESULT[0] 和 B.RESULT[1] 设置别名,以便为列指定唯一的名称:

create temp table bar as select array_construct(1, 2) as b;

-- This gets missing column specification
create temp table foo as select b[0], b[1] from bar;

-- This does not
create temp table foo as select b[0] as B0, b[1] as B1 from bar;