Skip to content

Commit e93e10f

Browse files
committed
readyset-sql: Convert SUBSTRING function
That's all the functions we support right now. Change-Id: I8e2e10c17bc598d1d65e6b245a2cde97dcf919ee
1 parent 5333150 commit e93e10f

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

readyset-sql/src/ast/expression.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -959,11 +959,19 @@ impl TryFromDialect<sqlparser::ast::Expr> for Expr {
959959
} => unsupported!("STRUCT"),
960960
Subquery(_query) => not_yet_implemented!("subquery"),
961961
Substring {
962-
expr: _,
963-
substring_from: _,
964-
substring_for: _,
962+
expr,
963+
substring_from,
964+
substring_for,
965965
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+
})),
967975
Trim {
968976
expr: _,
969977
trim_where: _,
@@ -1124,7 +1132,6 @@ impl TryFromDialect<sqlparser::ast::Function> for Expr {
11241132
ty: crate::ast::SqlType::Date,
11251133
postgres_style: false,
11261134
},
1127-
"extract" | "substring" => todo!(),
11281135
// TODO(mvzink): support COLLATE for upper and lower. nom-sql doesn't seem to parse
11291136
// collation here, and in the case of sqlparser-rs we would have to pull it out of the
11301137
// inner expression
@@ -1136,6 +1143,9 @@ impl TryFromDialect<sqlparser::ast::Function> for Expr {
11361143
expr: Box::new(exprs[0].clone()),
11371144
collation: None,
11381145
}),
1146+
name @ ("extract" | "substring") => {
1147+
return failed!("{name} should have been converted earlier")
1148+
}
11391149
_ => Self::Call(FunctionExpr::Call {
11401150
name: name.into_dialect(dialect),
11411151
arguments: exprs,

0 commit comments

Comments
 (0)