TIMESTAMP不一致导致BigQuery浏览器工具?

时间:2014-06-16 10:18:15

标签: google-bigquery

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

例如,要查询时间戳为> 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

发生了什么事?

1 个答案:

答案 0 :(得分:4)

可能会被一千人拒之门外。

见:

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