TRY_TO_TIMESTAMP

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

Analyze Syntax

func.try_to_timestamp(<expr>)

Analyze Examples

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:11                      2022-01-02 02:00:11                               NULL                                
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

SQL Syntax

-- 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>)

Aliases

SQL Examples

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') 
                Timestamp                                Timestamp               
├─────────────────────────────────────────┼────────────────────────────────────────┤
 2022-01-02 02:00:11                      2022-01-02 02:00:11                    
└──────────────────────────────────────────────────────────────────────────────────┘

SELECT TRY_TO_TIMESTAMP('databend'), TRY_TO_DATETIME('databend');

┌────────────────────────────────────────────────────────────┐
 try_to_timestamp('databend')  try_to_datetime('databend') 
├──────────────────────────────┼─────────────────────────────┤
 NULL                          NULL                        
└────────────────────────────────────────────────────────────┘
Last modified June 12, 2024 at 9:53 PM EST: updating datetime functions (f087f54)