gpt4 book ai didi

snowflake-cloud-data-platform - 如何获取雪花数据库中所有 View 的定义?

转载 作者:行者123 更新时间:2023-12-02 01:29:42 25 4
gpt4 key购买 nike

请求是从生产环境中获取所有 View 的定义并刷新下层环境。我认为,循环中的 GET_DDL 可以满足需要,但不确定如何实现它。请指教。

最佳答案

假设 VIEW_DEFITION 是不够的:

SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, VIEW_DEFINITION
FROM INFORMATION_SCHEMA.VIEWS
WHERE TABLE_SCHEMA != 'INFORMATION_SCHEMA';

GET_DDL是必需的:

DECLARE
CUR CURSOR FOR SELECT CONCAT_WS('.',TABLE_CATALOG,TABLE_SCHEMA,TABLE_NAME) AS name
FROM INFORMATION_SCHEMA.VIEWS
WHERE TABLE_SCHEMA NOT IN ('INFORMATION_SCHEMA');
BEGIN
CREATE OR REPLACE TEMPORARY TABLE temp_view_defs(view_name TEXT, definition TEXT);

FOR rec IN CUR DO
EXECUTE IMMEDIATE REPLACE('INSERT INTO temp_view_defs(view_name, definition)
SELECT ''<view_name>'', GET_DDL(''TABLE'', ''<view_name>'')'
,'<view_name>'
,rec.name);
END FOR;

LET rs RESULTSET := (SELECT * FROM temp_view_defs);

RETURN TABLE(rs);
END;

示例输出:

enter image description here

关于snowflake-cloud-data-platform - 如何获取雪花数据库中所有 View 的定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73596666/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com