python - 如何在 python 的 sqlsoup 中获取模式的列名?

标签 python mysql

如何在 python 中使用 SQLSOUP 从模式/表中获取字典中的列名和类型?使用 MySQLDB,我可以创建游标并使用 cursor.description。 sqlsoup 有一些等价物吗?

最佳答案

根据documentation :

A Table object can be instructed to load information about itself from the corresponding database schema object already existing within the database. This process is called reflection. In the most simple case you need only specify the table name, a MetaData object, and the autoload=True flag. If the MetaData is not persistently bound, also add the autoload_with argument:

>>> messages = Table('messages', meta, autoload=True, autoload_with=engine)
>>> [c.name for c in messages.columns]
['message_id', 'message_name', 'date']

关于python - 如何在 python 的 sqlsoup 中获取模式的列名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16467386/

相关文章:

Python计算给定日期范围内的记录数

MYSQL 查询待处理 `Purchase Order`

mysql - MySQL父子查询

MySQL 数组字段上的内连接

python - Cython 中的字符串操作

python - 如何从 python 或 ruby​​ 将 Excel 文件保存到亚马逊 s3

python - 在模板中使用特定的平面图

mysql - 在 SQL 中获取总耗时 (TIME)

mysql - 如何使用replace来更新列项

python - 如何将 POST 数据流式传输到 Python 请求中?