如何在python中打印bigquery的计数表查询?

时间:2019-10-10 11:33:59

标签: python google-bigquery selectcommand

我正在尝试在python中打印bigquery表中可用的行数,我编写了以下代码:

from google.cloud import bigquery def main():
    myquery = "select count(*) from `myproject.mydataset.mytable`"
    client = bigquery.Client()
    job = client.query(myquery)
    result = job.result()
    print("Total rows available: ",result)

当我执行上述代码时,它的输出为

  

“总可用行:google.cloud.bigquery.table.RowIterator对象   在0x00000247B65F29E8>”。

这意味着我正在获取对象值作为输出。 但我想打印表(查询结果)中可用的实际行数。

2 个答案:

答案 0 :(得分:1)

RowIterator has an attribute called total_rows.

只需将您的最后一个声明更改为

zend_extension=xdebug.so
xdebug.remote_enable=true
xdebug.remote_connect_back=true
xdebug.remote_autostart=true
xdebug.idekey=MY_AWESOME_KEY

答案 1 :(得分:1)

尝试将查询更改为

myquery = "select count(*) size from `myproject.mydataset.mytable`"
client = bigquery.Client()
job = client.query(myquery)
result = job.result()
for row in results:
    print("Total rows available: ",row.size)