BigQuery: convert epoch to TIMESTAMP

前端 未结 2 1028
忘掉有多难
忘掉有多难 2021-02-13 06:14

I\'m trying to range-join two tables, like so

SELECT *
FROM main_table h
INNER JOIN
    test.delay_pairs d
ON
    d.interval_start_time_utc < h.visitStartTime         


        
2条回答
  •  伪装坚强ぢ
    2021-02-13 07:03

    With standard sql you can use one of those, depending on precision:

    • DATE_FROM_UNIX_DATE - from days epoch to date
    • TIMESTAMP_SECONDS - from seconds epoch to timestamp
    • TIMESTAMP_MILLIS - from milliseconds epoch to timestamp
    • TIMESTAMP_MICROS - from microseconds epoch to timestamp

    See documentation here: https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#timestamp_seconds

    With legacy sql you can just use TIMESTAMP function and multiply or divide by 1000 to bring it to needed epoch type:

    SELECT 
      TIMESTAMP(epoch_in_millis / 1000) AS datetime
    FROM 
      my_table
    

提交回复
热议问题