Create a virtual timestamp
If you find you have no timestamp column available but you know how to compute your timestamp using a suitable column, you can create a virtual timestamp.
- Select the timestamp setting, and then click Create Virtual Timestamp +.
- In the form that appears, select a column with values you can turn into a timestamp using functions.
- Enter a function for converting the column's values into UTC-format timestamp values. For example, if you store timestamps as the epoch with millisecond precision, your input might be TO_TIMESTAMP({column_value}/1000).
- Enter a function for converting UTC-format timestamp values into valid column values, then select Save. For example, your input might be EXTRACT(epoch FROM {timestamp_value}) *1000.
Virtual timestamp function examples
The following two tables lists functions you can use to transform a column value to and from a timestamp value in each datasource— one for numeric column values and one for string column values. You can use these as a starting point, adjusting the transformation as needed to accommodate your column values.
Numeric column values
In these examples, the source column values are stored as the epoch with millisecond precision.
Database | columnToTimestamp | timestampToColumn |
---|---|---|
Athena | FROM_UNIXTIME({column_value} / 1000) | TO_UNIXTIME({timestamp_value}) * 1000 |
BigQuery | TIMESTAMP_MILLIS({column_value}) | UNIX_SECONDS({timestamp_value}) * 1000 |
Databricks | CAST(({column_value} / 1000) AS TIMESTAMP) | UNIX_TIMESTAMP({timestamp_value})::BIGINT * 1000 |
Dremio | TO_TIMESTAMP(CAST({column_value} AS BIGINT)/1000) | CAST(DATE_PART('EPOCH', {timestamp_value}) \* 1000 AS VARCHAR) |
Greenplum | TO_TIMESTAMP({column_value} / 1000) | EXTRACT(epoch FROM {timestamp_value}) * 1000 |
Hive | FROM_UNIXTIME(CAST({column_value} / 1000 AS BIGINT)) | UNIX_TIMESTAMP({timestamp_value}) * 1000 |
Microsoft SQL | DATEADD(s, {column_value} / 1000, '19700101') | CAST(DATEDIFF(s, '19700101', {timestamp_value}) <br><br>AS BIGINT) * 1000 |
Oracle | (timestamp '1970-01-01 00:00:00') + numtodsinterval({column_value} / 1000, 'second') | (CAST(SYS_EXTRACT_UTC({timestamp_value}) AS DATE) - DATE '1970-01-01' ) * 86400 * 1000 |
Postgres | TO_TIMESTAMP({column_value} / 1000) | EXTRACT(epoch FROM {timestamp_value}) * 1000 |
Redshift | TIMESTAMP 'epoch' + {column_value} / 1000 * interval '1 second' | EXTRACT(epoch FROM {timestamp_value})::bigint * 1000 |
Snowflake | TO_TIMESTAMP({column_value} / 1000) | EXTRACT(epoch FROM {timestamp_value}) * 1000 |
Teradata | TO_TIMESTAMP({column_value} / 1000) | CAST(((CAST(CAST({timestamp_value} AS TIMESTAMP) AS DATE AT 'GMT') - DATE '1970-01-01') * 86400 + (EXTRACT(HOUR FROM CAST({timestamp_value} AS TIMESTAMP) AT 'GMT') * 3600) + (EXTRACT(MINUTE FROM CAST({timestamp_value} AS TIMESTAMP) AT 'GMT') * 60) + (EXTRACT(SECOND FROM CAST({timestamp_value} AS TIMESTAMP)))) * 1000 AS BIGINT) |
String column values
In these examples, the source column values are stored as date/time strings with one-second precision, e.g., 2024-03-15 16:24:51
.
Database | columnToTimestamp | timestampToColumn |
---|---|---|
Athena | CHAR_TO_TIMESTAMP('yyyy-MM-dd-hh-mm-ss','{column_value}') | TIMESTAMP_TO_CHAR(yyyy-MM-dd-hh-mm-ss,{timestamp_value}); |
BigQuery | CAST({column_value} AS TIMESTAMP FORMAT YYYY-MM-DD-HH24-MI-SS) | UNIX_{timestamp_value} |
Databricks | CAST(({column_value}) AS TIMESTAMP) | UNIX_{timestamp_value})::BIGINT * 1000 |
Dremio | TO_TIMESTAMP(CAST({column_value} AS BIGINT)/1000) | CAST{timestamp_value} |
Greenplum | TO_TIMESTAMP({column_value} / 1000) | EXTRACT{timestamp_value} |
Hive | FROM_UNIXTIME(CAST({column_value} / 1000 AS BIGINT)) | {timestamp_value} |
Microsoft SQL | DATEADD(s, {column_value} / 1000, '19700101') | {timestamp_value} |
Oracle | (timestamp '1970-01-01 00:00:00') + numtodsinterval({column_value} / 1000, 'second') | {timestamp_value} |
Postgres | TO_TIMESTAMP({column_value} / 1000) | {timestamp_value} |
Redshift | TIMESTAMP 'epoch' + {column_value} / 1000 * interval '1 second' | EXTRACT({timestamp_value} |
Snowflake | TO_TIMESTAMP({column_value} / 1000) | EXTRACT {timestamp_value} |
Teradata | TO_TIMESTAMP({column_value} / 1000) | {timestamp_value} |
Updated 9 months ago