admin管理员组文章数量:1124776
I have this code of a procedure where I call a document AI build:
CREATE OR REPLACE PROCEDURE myproc()
RETURNS STRING
LANGUAGE SQL
EXECUTE AS CALLER
AS
BEGIN
CREATE OR REPLACE TEMPORARY TABLE my_table AS
SELECT
FILE_NAME,
DOCAI_BUILD_NAME!PREDICT(
GET_PRESIGNED_URL(@DOCS, FILE_NAME), 3
) AS pred
FROM mytable;
RETURN 'OK';
END;
Then this procedure is called by a task:
CREATE OR REPLACE TASK mytask
WAREHOUSE = mywarehouse
SCHEDULE = '1 minute'
USER_TASK_TIMEOUT_MS = 86400000
WHEN SYSTEM$STREAM_HAS_DATA('mystream')
AS
CALL myproc();
I want to set the version of Document AI build in a variable:
SET DOC_AI_VERSION = 3;
I want to use the variable set to the version of the DocumentAI build (which is here set to 3) directly from the variable that I set.
Also, is there a way to set the DocumentAI build name in a variable (which is set here to DOCAI_BUILD_NAME
) and also reference the variable inside the procedure.
I have tried to call the variable DOC_AI_VERSION
via GET_PRESIGNED_URL(@DOCS, FILE_NAME), $DOC_AI_VERSION
but this doesn't work. It logs an error:
$DOC_AI_VERSION' does not exist
I have this code of a procedure where I call a document AI build:
CREATE OR REPLACE PROCEDURE myproc()
RETURNS STRING
LANGUAGE SQL
EXECUTE AS CALLER
AS
BEGIN
CREATE OR REPLACE TEMPORARY TABLE my_table AS
SELECT
FILE_NAME,
DOCAI_BUILD_NAME!PREDICT(
GET_PRESIGNED_URL(@DOCS, FILE_NAME), 3
) AS pred
FROM mytable;
RETURN 'OK';
END;
Then this procedure is called by a task:
CREATE OR REPLACE TASK mytask
WAREHOUSE = mywarehouse
SCHEDULE = '1 minute'
USER_TASK_TIMEOUT_MS = 86400000
WHEN SYSTEM$STREAM_HAS_DATA('mystream')
AS
CALL myproc();
I want to set the version of Document AI build in a variable:
SET DOC_AI_VERSION = 3;
I want to use the variable set to the version of the DocumentAI build (which is here set to 3) directly from the variable that I set.
Also, is there a way to set the DocumentAI build name in a variable (which is set here to DOCAI_BUILD_NAME
) and also reference the variable inside the procedure.
I have tried to call the variable DOC_AI_VERSION
via GET_PRESIGNED_URL(@DOCS, FILE_NAME), $DOC_AI_VERSION
but this doesn't work. It logs an error:
Share Improve this question edited 2 days ago marc_s 754k183 gold badges1.4k silver badges1.5k bronze badges asked 2 days ago Mejdi DallelMejdi Dallel 136 bronze badges 1$DOC_AI_VERSION' does not exist
- You don't call a variable - you can only call code. You would use or reference that variable (or more precisely: its value) – marc_s Commented 2 days ago
1 Answer
Reset to default 1you can retrieve the value like (SELECT $DOC_AI_VERSION)
.
Setting the variable
SET DOC_AI_VERSION = 3;
Declare the variables in your procedure
CREATE OR REPLACE PROCEDURE myproc()
RETURNS STRING
LANGUAGE SQL
EXECUTE AS CALLER
AS
$$
DECLARE
DOC_AI_VERSION STRING;
SQL_STATEMENT STRING;
BEGIN
DOC_AI_VERSION := (SELECT $DOC_AI_VERSION);
SQL_STATEMENT := 'CREATE OR REPLACE TEMPORARY TABLE my_table AS
SELECT
FILE_NAME,
' || DOC_AI_VERSION || ' as variable_value
FROM mytable';
RETURN SQL_STATEMENT;
CALL myproc() ;
sql_statement prints as:
CREATE OR REPLACE TEMPORARY TABLE my_table AS
SELECT
FILE_NAME,
3 as variable_value
FROM mytable
本文标签: sqlHow to reference a variable set outside a procedure in SnowflakeStack Overflow
版权声明:本文标题:sql - How to reference a variable set outside a procedure in Snowflake? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736647009a1946131.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论