@@ -989,11 +989,19 @@ impl TryFromDialect<sqlparser::ast::Expr> for Expr {
989
989
} => unsupported ! ( "STRUCT" ) ,
990
990
Subquery ( _query) => not_yet_implemented ! ( "subquery" ) ,
991
991
Substring {
992
- expr : _ ,
993
- substring_from : _ ,
994
- substring_for : _ ,
992
+ expr,
993
+ substring_from,
994
+ substring_for,
995
995
special : _,
996
- } => not_yet_implemented ! ( "SUBSTRING" ) ,
996
+ } => Ok ( Self :: Call ( FunctionExpr :: Substring {
997
+ string : expr. try_into_dialect ( dialect) ?,
998
+ pos : substring_from
999
+ . map ( |expr| expr. try_into_dialect ( dialect) )
1000
+ . transpose ( ) ?,
1001
+ len : substring_for
1002
+ . map ( |expr| expr. try_into_dialect ( dialect) )
1003
+ . transpose ( ) ?,
1004
+ } ) ) ,
997
1005
Trim {
998
1006
expr : _,
999
1007
trim_where : _,
@@ -1152,7 +1160,6 @@ impl TryFromDialect<sqlparser::ast::Function> for Expr {
1152
1160
ty : crate :: ast:: SqlType :: Date ,
1153
1161
postgres_style : false ,
1154
1162
} ,
1155
- "extract" | "substring" => todo ! ( ) ,
1156
1163
// TODO(mvzink): support COLLATE for upper and lower. nom-sql doesn't seem to parse
1157
1164
// collation here, and in the case of sqlparser-rs we would have to pull it out of the
1158
1165
// inner expression
@@ -1164,6 +1171,9 @@ impl TryFromDialect<sqlparser::ast::Function> for Expr {
1164
1171
expr : Box :: new ( exprs[ 0 ] . clone ( ) ) ,
1165
1172
collation : None ,
1166
1173
} ) ,
1174
+ name @ ( "extract" | "substring" ) => {
1175
+ return failed ! ( "{name} should have been converted earlier" )
1176
+ }
1167
1177
_ => Self :: Call ( FunctionExpr :: Call {
1168
1178
name : name. into_dialect ( dialect) ,
1169
1179
arguments : exprs,
0 commit comments