@@ -959,11 +959,19 @@ impl TryFromDialect<sqlparser::ast::Expr> for Expr {
959
959
} => unsupported ! ( "STRUCT" ) ,
960
960
Subquery ( _query) => not_yet_implemented ! ( "subquery" ) ,
961
961
Substring {
962
- expr : _ ,
963
- substring_from : _ ,
964
- substring_for : _ ,
962
+ expr,
963
+ substring_from,
964
+ substring_for,
965
965
special : _,
966
- } => not_yet_implemented ! ( "SUBSTRING" ) ,
966
+ } => Ok ( Self :: Call ( FunctionExpr :: Substring {
967
+ string : expr. try_into_dialect ( dialect) ?,
968
+ pos : substring_from
969
+ . map ( |expr| expr. try_into_dialect ( dialect) )
970
+ . transpose ( ) ?,
971
+ len : substring_for
972
+ . map ( |expr| expr. try_into_dialect ( dialect) )
973
+ . transpose ( ) ?,
974
+ } ) ) ,
967
975
Trim {
968
976
expr : _,
969
977
trim_where : _,
@@ -1124,7 +1132,6 @@ impl TryFromDialect<sqlparser::ast::Function> for Expr {
1124
1132
ty : crate :: ast:: SqlType :: Date ,
1125
1133
postgres_style : false ,
1126
1134
} ,
1127
- "extract" | "substring" => todo ! ( ) ,
1128
1135
// TODO(mvzink): support COLLATE for upper and lower. nom-sql doesn't seem to parse
1129
1136
// collation here, and in the case of sqlparser-rs we would have to pull it out of the
1130
1137
// inner expression
@@ -1136,6 +1143,9 @@ impl TryFromDialect<sqlparser::ast::Function> for Expr {
1136
1143
expr : Box :: new ( exprs[ 0 ] . clone ( ) ) ,
1137
1144
collation : None ,
1138
1145
} ) ,
1146
+ name @ ( "extract" | "substring" ) => {
1147
+ return failed ! ( "{name} should have been converted earlier" )
1148
+ }
1139
1149
_ => Self :: Call ( FunctionExpr :: Call {
1140
1150
name : name. into_dialect ( dialect) ,
1141
1151
arguments : exprs,
0 commit comments