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
With standard sql you can use one of those, depending on precision:
DATE_FROM_UNIX_DATE
- from days epoch to dateTIMESTAMP_SECONDS
- from seconds epoch to timestampTIMESTAMP_MILLIS
- from milliseconds epoch to timestampTIMESTAMP_MICROS
- from microseconds epoch to timestampSee 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
You can use timestamp conversion functions like TIMESTAMP_SECONDS
, TIMESTAMP_MILLIS
, TIMESTAMP_MICROS
for example, assuming your h.visitStartTime is microseconds since the unix epoch
SELECT *
FROM main_table h
INNER JOIN test.delay_pairs d
ON d.interval_start_time_utc < TIMESTAMP_MICROS(h.visitStartTime)
AND TIMESTAMP_MICROS(h.visitStartTime) < d.interval_end_time_utc