如何使用 table 名称中的过程参数在雪花过程中创建临时 table
how to create the temporary table in snowflake procedure with procedure parameter in table name
create or replace procedure test_table_proc(ingestion varchar)
returns varchar
language javascript
as
$$
var step2="create or replace temporary table FN_IGSN_ROLE_PLAYER_NAME_OUTPUT_TEMP"
step2+=ingestion
step2+=" as select * from bv_principal limit 10";
var statement2=snowflake.createStatement( {sqlText: step2,binds: [ingestion]} );
statement2.execute();
$$
create or replace procedure test_table_proc("ingestion" varchar)
returns varchar
language javascript
execute as owner
as
$$
let step2 =
`
create or replace temporary table FN_IGSN_ROLE_PLAYER_NAME_OUTPUT_TEMP_${ingestion}
as select * from bv_principal limit 10
`;
var statement2=snowflake.createStatement( {sqlText: step2} );
statement2.execute();
$$;
call test_table_proc('SUFFIX');
您不能将变量绑定到部分 table 名称,因此您可以删除绑定。字符串连接会很快变得不整洁,因此您可以使用反引号 ` 打开和关闭字符串,并使用 ${variableName} 语法替换值。我还建议使用 let
来定义变量,除非你理解 let
和 var
之间的区别。
create or replace procedure test_table_proc(ingestion varchar)
returns varchar
language javascript
as
$$
var step2="create or replace temporary table FN_IGSN_ROLE_PLAYER_NAME_OUTPUT_TEMP"
step2+=ingestion
step2+=" as select * from bv_principal limit 10";
var statement2=snowflake.createStatement( {sqlText: step2,binds: [ingestion]} );
statement2.execute();
$$
create or replace procedure test_table_proc("ingestion" varchar)
returns varchar
language javascript
execute as owner
as
$$
let step2 =
`
create or replace temporary table FN_IGSN_ROLE_PLAYER_NAME_OUTPUT_TEMP_${ingestion}
as select * from bv_principal limit 10
`;
var statement2=snowflake.createStatement( {sqlText: step2} );
statement2.execute();
$$;
call test_table_proc('SUFFIX');
您不能将变量绑定到部分 table 名称,因此您可以删除绑定。字符串连接会很快变得不整洁,因此您可以使用反引号 ` 打开和关闭字符串,并使用 ${variableName} 语法替换值。我还建议使用 let
来定义变量,除非你理解 let
和 var
之间的区别。