GBQ | Python:如何检索表中所有列的数据类型?

时间:2018-02-18 23:55:21

标签: python google-bigquery

我使用下面的代码来获取列的列表,它可以正常工作。

table_ref = dataset_ref.table(table_name)
table = client.get_table(table_ref)
field_names = [field.name for field in table.schema]

但是当我尝试使用下面的代码来获取数据类型时,我收到了一个错误 - AttributeError:' SchemaField'对象没有属性'键入'

field_types = [field.type for field in table.schema]

1 个答案:

答案 0 :(得分:2)

请改为尝试:

field_types = [field.field_type for field in table.schema]

因为看起来属性名称是field_type而不仅仅是"输入"。

相关问题