使用SQLAlchemy检查Snowflake表上的列时,列注释不可见。
pip install snowflake-sqlalchemy
测试
import sqlalchemy
# set up the connection
snowflake_conn = '<your-connection-string-here>'
engine = sqlalchemy.create_engine(snowflake_conn)
# create a table for testing, add a column comment
engine.execute('create table public.test ("col1" text);')
engine.execute("""alter table public.test alter "col1" comment 'this is my comment'""")
# check if comment is successfully stored in the information schema
engine.execute("select comment from information_schema.columns where table_name='TEST'").fetchall()
# Output: [('this is my comment',)]
# now let's try to inspect the table
inspector = sqlalchemy.inspect(engine)
inspector.get_columns('TEST', schema='PUBLIC')
实际结果
[{'name': 'col1',
'type': VARCHAR(length=16777216),
'nullable': True,
'default': None,
'autoincrement': False,
'primary_key': False}]
预期结果
[{'name': 'col1',
'type': VARCHAR(length=16777216),
'nullable': True,
'default': None,
'comment': 'this is my comment', # <-- this is added
'autoincrement': False,
'primary_key': False}]
我在检查列注释时做错什么了吗,或者这仅仅是雪花SQLAlchemy中的错误?
答案 0 :(得分:1)
感谢您发表您的发现!
这似乎是snowflake-sqlalchemy
中的问题,我们已经开始调查此问题,请关注此处以获取更新:https://github.com/snowflakedb/snowflake-sqlalchemy/issues/90
答案 1 :(得分:1)
我刚刚使用snowflake-sqlalchemy==1.1.18
测试了您(准备充分的)代码,并且注释已按预期返回。
{
'name' : 'col1',
'primary_key' : False,
'default' : 'None',
'type' : VARCHAR(length=16777216),
'nullable' : True,
'autoincrement' : False,
'comment' : 'this is my comment'
}