雪花炼金术无法检查列注释

2024-03-29 10:32:15 发布

您现在位置:Python中文网/ 问答频道 /正文

问题

使用SQLAlchemy检查雪花表上的列时,列注释不可见。你知道吗

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}]

问题

我检查专栏评论是做错了什么,还是这仅仅是雪花sqlalchemy中的一个bug?你知道吗


Tags: thenamefalseexecutesqlalchemyisschemamy
2条回答

感谢您发布您的发现!你知道吗

这似乎是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'
}

相关问题 更多 >