@@ -1223,25 +1223,47 @@ impl<'a> Parser<'a> {
12231223 }
12241224
12251225 pub fn parse_substring_expr ( & mut self ) -> Result < Expr , ParserError > {
1226- // PARSE SUBSTRING (EXPR [FROM 1] [FOR 3])
1227- self . expect_token ( & Token :: LParen ) ?;
1228- let expr = self . parse_expr ( ) ?;
1229- let mut from_expr = None ;
1230- if self . parse_keyword ( Keyword :: FROM ) || self . consume_token ( & Token :: Comma ) {
1231- from_expr = Some ( self . parse_expr ( ) ?) ;
1232- }
1226+ if self . dialect . supports_substring_from_for_expr ( ) {
1227+ // PARSE SUBSTRING (EXPR [FROM 1] [FOR 3])
1228+ self . expect_token ( & Token :: LParen ) ?;
1229+ let expr = self . parse_expr ( ) ?;
1230+ let mut from_expr = None ;
1231+ if self . parse_keyword ( Keyword :: FROM ) || self . consume_token ( & Token :: Comma ) {
1232+ from_expr = Some ( self . parse_expr ( ) ?) ;
1233+ }
12331234
1234- let mut to_expr = None ;
1235- if self . parse_keyword ( Keyword :: FOR ) || self . consume_token ( & Token :: Comma ) {
1236- to_expr = Some ( self . parse_expr ( ) ?) ;
1237- }
1238- self . expect_token ( & Token :: RParen ) ?;
1235+ let mut to_expr = None ;
1236+ if self . parse_keyword ( Keyword :: FOR ) || self . consume_token ( & Token :: Comma ) {
1237+ to_expr = Some ( self . parse_expr ( ) ?) ;
1238+ }
1239+ self . expect_token ( & Token :: RParen ) ?;
12391240
1240- Ok ( Expr :: Substring {
1241- expr : Box :: new ( expr) ,
1242- substring_from : from_expr. map ( Box :: new) ,
1243- substring_for : to_expr. map ( Box :: new) ,
1244- } )
1241+ Ok ( Expr :: Substring {
1242+ expr : Box :: new ( expr) ,
1243+ substring_from : from_expr. map ( Box :: new) ,
1244+ substring_for : to_expr. map ( Box :: new) ,
1245+ special : !self . dialect . supports_substring_from_for_expr ( ) ,
1246+ } )
1247+ } else {
1248+ // PARSE SUBSTRING(EXPR, start, length)
1249+ self . expect_token ( & Token :: LParen ) ?;
1250+ let expr = self . parse_expr ( ) ?;
1251+
1252+ self . expect_token ( & Token :: Comma ) ?;
1253+ let from_expr = Some ( self . parse_expr ( ) ?) ;
1254+
1255+ self . expect_token ( & Token :: Comma ) ?;
1256+ let to_expr = Some ( self . parse_expr ( ) ?) ;
1257+
1258+ self . expect_token ( & Token :: RParen ) ?;
1259+
1260+ Ok ( Expr :: Substring {
1261+ expr : Box :: new ( expr) ,
1262+ substring_from : from_expr. map ( Box :: new) ,
1263+ substring_for : to_expr. map ( Box :: new) ,
1264+ special : !self . dialect . supports_substring_from_for_expr ( ) ,
1265+ } )
1266+ }
12451267 }
12461268
12471269 pub fn parse_overlay_expr ( & mut self ) -> Result < Expr , ParserError > {
0 commit comments