如何在BQ中基于timestamp列创建分区表

时间:2018-05-24 02:29:43

标签: google-bigquery

在下表中,只有两列(ts和transaction_id)和3行。我只是尝试基于时间戳列创建分区表,但是我收到错误消息。

create table myfirstdataset.partition_table1(ts timestamp, transaction_id int64)partition by ts as
select timestamp '2013-12-31 01:55:02.000 UTC' ts, 10 transaction_id union all
select timestamp '2013-12-31 02:10:02.000 UTC' ts, 5 transaction_id union all
select timestamp '2013-12-31 04:20:02.000 UTC' ts, 6 transaction_id 

Error: PARTITION BY expression must be DATE(<timestamp_column>) or else a DATE column

1 个答案:

答案 0 :(得分:4)

应该是PARTITION BY DATE(ts)而不是PARTITION BY ts - 请特别注明CREATE TABLE statementpartition_expression

create table myfirstdataset.partition_table1(ts timestamp, transaction_id int64)partition by date(ts) as
select timestamp '2013-12-31 01:55:02.000 UTC' ts, 10 transaction_id union all
select timestamp '2013-12-31 02:10:02.000 UTC' ts, 5 transaction_id union all
select timestamp '2013-12-31 04:20:02.000 UTC' ts, 6 transaction_id