You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the target sql is "select * from table2 where id in (SELECT id FROM table1 WHERE find_in_set(100, ancestors))"
the follow code will throw exception that Statement cant convert to Expression
InExpression expression = new InExpression();
expression.setLeftExpression(new Column(deptColumn));
Statement subSelect = CCJSqlParserUtil.parse("SELECT id FROM table1 WHERE find_in_set(100, ancestors)");
expression.setRightExpression((Expression) subSelect);
It's just pure coincidence, that I have provided PR #1754 which changes exactly that behaviour and makes the former SubSelect a normal Statement (and Expression).
So when you checkout this PR #1754, the following will work:
@TestvoidtestSubJoinParsing() throwsJSQLParserException {
StringsqlStr = "(SELECT id FROM table1 WHERE find_in_set(100, ancestors))";
Selectselect = (Select) CCJSqlParserUtil.parse(sqlStr);
InExpressioninExpression = newInExpression();
inExpression.setLeftExpression(newColumn("id"));
inExpression.setRightExpression( select );
Assertions.assertEquals("id IN (SELECT id FROM table1 WHERE find_in_set(100, ancestors))", inExpression.toString());
}
Activity
manticore-projects commentedon Apr 14, 2023
Greetings.
Yes, your observation is correct because
SubSelectis anExpression, but not aStatement.So you have to options:
SubSelectusing the Java API.SubSelectas an Expression:manticore-projects commentedon Apr 14, 2023
It's just pure coincidence, that I have provided PR #1754 which changes exactly that behaviour and makes the former
SubSelecta normal Statement (and Expression).So when you checkout this PR #1754, the following will work: