【问题标题】:Inconsistent TIMESTAMP results in BigQuery browser tool?BigQuery 浏览器工具中的 TIMESTAMP 不一致?
【发布时间】:2014-06-16 10:18:14
【问题描述】:

我正在尝试在时间戳字段上查询表,但我得到了一些奇怪的结果。

例如,查询时间戳为> 1402913235(根据http://www.epochconverter.com6 Jun 2014 10:07:15 GMT)的行返回ff:

SELECT timestamp FROM [MyTable]
where timestamp > 1402913235 
order by timestamp LIMIT 20;

Results:
--------
Row timestamp    
1   2009-02-13 23:31:30 UTC  
2   2009-02-13 23:31:30 UTC  
3   2009-02-13 23:31:30 UTC  
4   2009-02-13 23:31:30 UTC  
5   2009-02-13 23:31:35 UTC

Downloaded Raw CSV:
-------------------
timestamp
1.23456789E9
1.23456789E9
1.23456789E9
1.23456789E9
1.234567895E9

很明显,前5个结果不大于1402913235

同一张表的另一个例子:

SELECT timestamp FROM [MyTable]
order by timestamp desc LIMIT 20;

Results:
--------
Row timestamp    
1   46426-07-19 16:15:18 UTC     
2   46426-07-19 14:45:44 UTC     
3   46426-07-19 14:44:40 UTC     
4   46426-07-19 14:34:12 UTC     
5   46426-07-19 09:17:21 UTC

Downloaded Raw CSV:
-------------------
timestamp
1.4029131465180002E12
1.402913141144E12
1.40291314108E12
1.402913140452E12
1.402913121441E12

同样,根据epochconverter.com,第一个结果应该是1.4029131465180002E12 == 1402913146518.0002 == 16 Jun 2014 10:05:46 GMT而不是46426-07-19 16:15:18

发生了什么事?

【问题讨论】:

  • 你在使用 Streak 插件吗?
  • 有时可以,但已禁用。

标签: google-bigquery


【解决方案1】:

可能相差一千。

看这个:

SELECT USEC_TO_TIMESTAMP(1402913146518) as_usec, 
       MSEC_TO_TIMESTAMP(1402913146518) as_msec,
       SEC_TO_TIMESTAMP(1402913146518) as_sec

as_usec                  as_msec                    as_sec   
1970-01-17 05:41:53 UTC  2014-06-16 10:05:46 UTC    46426-07-19 16:15:18 UTC     

第一个问题,比较之前记得先转换成时间戳:

SELECT 
  as_msec > (1402913146518+100) timestamp_more_than_number,
  as_msec > MSEC_TO_TIMESTAMP(1402913146518+100) timestamp_more_than_timestamp
FROM (SELECT MSEC_TO_TIMESTAMP(1402913146518) as_msec)

timestamp_more_than_number  timestamp_more_than_timestamp    
true                        false

【讨论】:

  • 谢谢。所以浏览器工具期望时间戳以秒为单位?我应该将所有时间戳数据存储为秒?
  • 在将列导入为时间戳时,请参阅 developers.google.com/bigquery/timestamp 以了解可接受的格式。导入后,它们既不是秒也不是毫秒,而是时间戳 - 将它们与时间戳进行比较或将它们转换为您喜欢的表示形式。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-07
  • 2011-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多