@@ -243,7 +243,8 @@ impl<'a> Parser<'a> {
243243 Ok ( Expr :: Value ( self . parse_value ( ) ?) )
244244 }
245245 Keyword :: CASE => self . parse_case_expr ( ) ,
246- Keyword :: CAST => self . parse_cast_expr ( ) ,
246+ Keyword :: CAST => self . parse_cast_expr ( false ) ,
247+ Keyword :: TRY_CAST => self . parse_cast_expr ( true ) ,
247248 Keyword :: EXISTS => self . parse_exists_expr ( ) ,
248249 Keyword :: EXTRACT => self . parse_extract_expr ( ) ,
249250 Keyword :: INTERVAL => self . parse_literal_interval ( ) ,
@@ -481,13 +482,14 @@ impl<'a> Parser<'a> {
481482 }
482483
483484 /// Parse a SQL CAST function e.g. `CAST(expr AS FLOAT)`
484- pub fn parse_cast_expr ( & mut self ) -> Result < Expr , ParserError > {
485+ pub fn parse_cast_expr ( & mut self , try_cast : bool ) -> Result < Expr , ParserError > {
485486 self . expect_token ( & Token :: LParen ) ?;
486487 let expr = self . parse_expr ( ) ?;
487488 self . expect_keyword ( Keyword :: AS ) ?;
488489 let data_type = self . parse_data_type ( ) ?;
489490 self . expect_token ( & Token :: RParen ) ?;
490491 Ok ( Expr :: Cast {
492+ try_cast,
491493 expr : Box :: new ( expr) ,
492494 data_type,
493495 } )
@@ -853,6 +855,7 @@ impl<'a> Parser<'a> {
853855 /// Parse a postgresql casting style which is in the form of `expr::datatype`
854856 pub fn parse_pg_cast ( & mut self , expr : Expr ) -> Result < Expr , ParserError > {
855857 Ok ( Expr :: Cast {
858+ try_cast : false ,
856859 expr : Box :: new ( expr) ,
857860 data_type : self . parse_data_type ( ) ?,
858861 } )
0 commit comments