Snowflake-sqlalchemy 无法检查列注释
Snowflake-sqlalchemy can't inspect column comments
问题
使用 SQLAlchemy 检查 Snowflake 表上的列时,列注释不可见。
MCVE
要求
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 中的一个错误?
感谢您发布您的发现!
这似乎是snowflake-sqlalchemy
中的一个问题,我们已经开始调查这个问题,请关注这里的更新:https://github.com/snowflakedb/snowflake-sqlalchemy/issues/90
我刚刚用 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'
}
问题
使用 SQLAlchemy 检查 Snowflake 表上的列时,列注释不可见。
MCVE
要求
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 中的一个错误?
感谢您发布您的发现!
这似乎是snowflake-sqlalchemy
中的一个问题,我们已经开始调查这个问题,请关注这里的更新:https://github.com/snowflakedb/snowflake-sqlalchemy/issues/90
我刚刚用 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'
}