Skip to content

A variant of TO_TIMESTAMP in PlaidCloud Lakehouse that, while performing the same conversion of an input expression to a timestamp, incorporates error-handling support by returning NULL if the conversion fails instead of raising an error.

See also: TO_TIMESTAMP

func.try_to_timestamp(<expr>)
func.try_to_timestamp('2022-01-02 02:00:11'), func.try_to_datetime('2022-01-02 02:00:11'), func.try_to_timestamp('plaidcloud')
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ func.try_to_timestamp('2022-01-02 02:00:11') │ func.try_to_datetime('2022-01-02 02:00:11') │ func.try_to_timestamp('plaidcloud') │
│ Timestamp │ Timestamp │ │
├─────────────────────────────────────────┼──────────────────────────────────────────────────┤─────────────────────────────────────│
2022-01-02 02:00:112022-01-02 02:00:11NULL
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
-- Convert a string or integer to a timestamp
TRY_TO_TIMESTAMP(<expr>)
-- Convert a string to a timestamp using the given pattern
TRY_TO_TIMESTAMP(<expr, expr>)
SELECT TRY_TO_TIMESTAMP('2022-01-02 02:00:11'), TRY_TO_DATETIME('2022-01-02 02:00:11');
┌──────────────────────────────────────────────────────────────────────────────────┐
│ try_to_timestamp('2022-01-02 02:00:11') │ try_to_datetime('2022-01-02 02:00:11') │
TimestampTimestamp
├─────────────────────────────────────────┼────────────────────────────────────────┤
2022-01-02 02:00:112022-01-02 02:00:11
└──────────────────────────────────────────────────────────────────────────────────┘
SELECT TRY_TO_TIMESTAMP('databend'), TRY_TO_DATETIME('databend');
┌────────────────────────────────────────────────────────────┐
│ try_to_timestamp('databend') │ try_to_datetime('databend') │
├──────────────────────────────┼─────────────────────────────┤
NULLNULL
└────────────────────────────────────────────────────────────┘