如何检索雪花等数据库中的所有目录名、模式名和表名? [英] How to retrieve all the catalog names , schema names and the table names in a database like snowflake or any such database?

查看:34
本文介绍了如何检索雪花等数据库中的所有目录名、模式名和表名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要删除一些列,并将雪花表中的数据大写。 为此,我需要遍历所有的目录/数据库、其各自的模式,然后是表。 我需要它在Python中列出目录架构,然后列出表格,在这些表格之后,我将启动SQL查询来执行操作。

如何进行此操作?

1.列出所有目录名称

2.列出所有架构名称

3.列出所有表名

我已使用python雪花连接器建立了连接

推荐答案

您可能不需要RESULT_SCAN。最近,我创建了一个python程序来列出Snowflake中所有表的所有列。我的要求是验证每个列并计算列的一些数字统计信息。我只用了"Show Columns"就可以做到这一点。我已经开源了一些常见的雪花操作,可以在这里找到

https://github.com/Infosys/Snowflake-Python-Development-Framework

您可以克隆此代码,然后使用此框架创建Python程序,如下所示列出列,然后您可以随心所欲地处理列详细信息

##
from utilities.sf_operations import Snowflakeconnection

connection = Snowflakeconnection(profilename ='snowflake_host')
sfconnectionresults = connection.get_snowflake_connection()

sfconnection = sfconnectionresults.get('connection')
statuscode = sfconnectionresults.get('statuscode')
statusmessage = sfconnectionresults.get('statusmessage')

print(sfconnection,statuscode,statusmessage)

snow_sql = 'SHOW COLUMNS;'
queryresult = connection.execute_snowquery(sfconnection,snow_sql);
print(queryresult['result'])
print('column_name|table_name|column_attribute')
print('---------------------------------------------')
for rows in queryresult['result']:
    table_name = rows[0]
    schema_name = rows[1]
    column_name = rows[2]
    column_attribute = rows[3]
    is_Null = rows[4]
    default_Value = rows[5]
    kind = rows[6]
    expression = rows[7]
    comment = rows[8]
    database_name = rows[9]
    autoincrement = rows[10]

    print(column_name+'|'+table_name+'|'+column_attribute)

这篇关于如何检索雪花等数据库中的所有目录名、模式名和表名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆