Joyce
Joyce

Reputation: 1451

TIMESTAMP_SECONDS parsing errors

I've been trying to use the TIMESTAMP_SECONDS function to convert some epoch timestamps in seconds format, but I have some bad data. Is there such a thing as SAFE_TIMESTAMP?

Thank you

Upvotes: 1

Views: 1442

Answers (1)

Elliott Brossard
Elliott Brossard

Reputation: 33765

Is there such a thing as SAFE_TIMESTAMP

There is! It's called SAFE.TIMESTAMP_SECONDS. You can apply the SAFE. prefix to functions to make them return NULL instead of an error; see the documentation for more reading. For example:

SELECT SAFE.TIMESTAMP_SECONDS(0xFFFFFFFFFFFFFF);
+------+
| f0_  |
+------+
| NULL |
+------+

For a valid number of seconds since the epoch:

SELECT SAFE.TIMESTAMP_SECONDS(1539973868);
+------------------------+
| f0_                    |
+------------------------+
| 2018-10-19 18:31:08+00 |
+------------------------+

Upvotes: 2

Related Questions