feat: Support ANY/ALL operators#477
Conversation
|
@alamb WDYT? Should I create a separate issue for supporting AllOperatorSubquery & AnyOperatorSubQuery? |
Pull Request Test Coverage Report for Build 2277494621
💛 - Coveralls |
alamb
left a comment
There was a problem hiding this comment.
Ho @ovr --- sounds like an exiting feature!
Looking at the postgres documentation, https://www.postgresql.org/docs/current/functions-subquery.html it seems to me like ANY / ALL can be combined with any operator that results in a boolean, not just <, <=, =, !=, >=, >
For example, with ~:
alamb=# select x from test where x ~ ANY (select x from test);
x
-----
foo
(1 row)What would you think about adding something like
/// `ANY()`
Any(Box<Expr>),This might be more in keeping with the spirit of sql-parser-rs to parse the query faithfully without applying any implicit semantics to it.
@alamb WDYT? Should I create a separate issue for supporting AllOperatorSubquery & AnyOperatorSubQuery?
I don't think separate issues are necessary
|
@alamb Oh, I see, but anyway what about LIKE/AND/OR operators which are supported in Binary expression but is not supported for If it's okey, I will update a PR to reflect your idea. Big thanks to you! |
I am not quite sure what you mean about " Maybe you could do something like the following with a match guard (totally untested): sqlparser::Expr::BinaryExpr {
left,
op
right
} if is_any_expr(&right) => {...}
}
...and /// returns true of `expr` represents an `Any` clause
fn is_any_expr(expr: sqlparser::Expr) ->bool) {
...
}I found this style worked pretty well in simplify_expressions: |
37d0338 to
69eceab
Compare
|
@alamb Oh, I see your idea about simplifying it and wrapping it on the right side of the BinaryExpression expression. I've updated the PR as you suggested. Thanks |
| right: Box<Expr>, | ||
| }, | ||
| /// Any operation e.g. `1 ANY (1)` or `foo > ANY(bar)`, It will be wrapped in the right side of BinaryExpr | ||
| AnyOp(Box<Expr>), |
| SelectItem::UnnamedExpr(Expr::BinaryOp { | ||
| left: Box::new(Expr::Identifier(Ident::new("a"))), | ||
| op: BinaryOperator::Eq, | ||
| right: Box::new(Expr::AnyOp(Box::new(Expr::Identifier(Ident::new("b"))))), |
* feat: Support ANY/ALL operators * fix lint
Hello!
Ref issue: #476
I want to support
a = ANY(expr)in DF, but after reviewing I come to decision that it requires changes insql-parserto simplify code (because hacking when the right side is a function is a super tricky)Thanks