使用 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}]
问题
我在检查列注释时做错了什么,或者这只是snowflake-sqlalchemy 中的一个错误?
撒科打诨
12345678_0001
相关分类