如果您需要在BigQuery中创建一个不带任何排序规则的数据集,请按照以下步骤:
SELECT ORDINAL_POSITION, COLUMN_NAME, COLLATION_NAME
FROM project_id.dataset_id.INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'table_name'
如果 COLLATION_NAME 字段显示为空字符串,则表中不存在排序规则。
示例代码如下:
from google.cloud import bigquery
client = bigquery.Client()
dataset_id = 'new_dataset'
dataset_ref = client.dataset(dataset_id)
dataset = bigquery.Dataset(dataset_ref)
dataset.default_collation = ""
client.create_dataset(dataset)
table_id = 'new_dataset.new_table'
schema = [ bigquery.SchemaField('id', 'INTEGER'), bigquery.SchemaField('name', 'STRING'), bigquery.SchemaField('age', 'INTEGER'), ]
table_ref = dataset_ref.table(table_id) table = bigquery.Table(table_ref, schema=schema) table = client.create_table(table)
rows_to_insert = [ (1, 'John Doe', 30), (2, 'Jane Smith', 25), (3, 'Bob Johnson', 40), ] client.insert_rows(table, rows_to_insert)
query = """
SELECT ORDINAL_POSITION, COLUMN_NAME, COLLATION_NAME
FROM {}.{}.INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = '{}'
""".format(dataset_id, dataset_id, 'new_table')
query_job = client.query(query)
for row in query_job: print(row)
下一篇:BigQuery数据集维护