BigQuery 检查表是否存在 [英] BigQuery check if table exists or not
问题描述
我正在使用 C# 根据来自 bigquery api 表端点的响应动态构建查询.我正在尝试计算有效的活跃用户,但前提是我选择每个带有 .*
的表.我的问题真的很简单,有没有办法检查 BigQuery SQL 中是否存在表?
I'm using C# to dynamically construct a query based on a response from the bigquery api tables endpoint. I'm trying to calculate active users which works, but only if I select every table with .*
. My question is quite simple really, is there a way to check if a table exists within BigQuery SQL?
推荐答案
有名为 __TABLES__
和 __TABLES_SUMMARY__
您可以运行如下查询:
SELECT size_bytes FROM <dataset>.__TABLES__ WHERE table_id='mytablename'
该查询的 __TABLES__
部分可能看起来不熟悉.__TABLES_SUMMARY__
是一个元表,包含有关数据集中表的信息.你可以自己使用这个元表.例如,查询 SELECT * FROM publicdata:samples.__TABLES_SUMMARY__
将返回有关 publicdata:samples
数据集中表的元数据.你也可以做 SELECT * FROM publicdata:samples.__TABLES__
The __TABLES__
portion of that query may look unfamiliar. __TABLES_SUMMARY__
is a meta-table containing information about tables in a dataset. You can use this meta-table yourself. For example, the query SELECT * FROM publicdata:samples.__TABLES_SUMMARY__
will return metadata about the tables in the publicdata:samples
dataset. You can also do SELECT * FROM publicdata:samples.__TABLES__
可用字段:
__TABLES_SUMMARY__
元表的字段(在 TABLE_QUERY
查询中都可用)包括:
The fields of the __TABLES_SUMMARY__
meta-table (that are all available in the TABLE_QUERY
query) include:
table_id
:表名.creation_time
:创建表的时间,以 UTC 时间 1/1/1970 以来的毫秒数为单位.这与表中的creation_time
字段相同.type
:是视图(2)还是普通表(1).
table_id
: name of the table.creation_time
: time, in milliseconds since 1/1/1970 UTC, that the table was created. This is the same as thecreation_time
field on the table.type
: whether it is a view (2) or regular table (1).
以下字段在 TABLE_QUERY()
中不可用,因为它们是 __TABLES__
的成员,但不是 __TABLES_SUMMARY__
.它们被保留在这里是为了历史兴趣并部分记录 __TABLES__
元表:
The following fields are not available in TABLE_QUERY()
since they are members of __TABLES__
but not __TABLES_SUMMARY__
. They're kept here for historical interest and to partially document the __TABLES__
metatable:
last_modified_time
:时间,自 1970 年 1 月 1 日 UTC 起更新表(元数据或表内容)的毫秒数.请注意,如果您使用tabledata.insertAll()
将记录流式传输到您的表,这可能会过时几分钟.row_count
:表中的行数.size_bytes
:表的总大小(以字节为单位).
last_modified_time
: time, in milliseconds since 1/1/1970 UTC, that the table was updated (either metadata or table contents). Note that if you use thetabledata.insertAll()
to stream records to your table, this might be a few minutes out of date.row_count
: number of rows in the table.size_bytes
: total size in bytes of the table.
这篇关于BigQuery 检查表是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!