Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -5699,11 +5699,19 @@ public class CCJSqlParser extends AbstractJSqlParser<CCJSqlParser> {
*/
protected boolean isNamedExprListAhead() {
int depth = 0;
// IN, FROM inside CASE ... END belong to the CASE branches, not to the function
int caseDepth = 0;
for (Token t = getToken(1); ; t = nextWithItemToken(t)) {
if (t.kind == EOF) {
return false;
}
if (t.kind == OPENING_BRACKET) {
if (t.kind == K_CASE) {
caseDepth++;
} else if (t.kind == K_END && caseDepth > 0) {
caseDepth--;
} else if (caseDepth > 0) {
continue;
} else if (t.kind == OPENING_BRACKET) {
depth++;
} else if (t.kind == CLOSING_BRACKET) {
if (depth == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6764,4 +6764,12 @@ void testSnowflakeCastsAndLateralFlattenRegression() throws Exception {
TestUtils.assertSqlCanBeParsedAndDeparsed(
"SELECT user.value FROM t, LATERAL FLATTEN(input => t.data:users) user", true);
}

@Test
void testStringFunctionWithInPredicateInsideCase() throws JSQLParserException {
TestUtils.assertSqlCanBeParsedAndDeparsed(
"SELECT SUBSTR(CASE WHEN x IN (1, 2) THEN 'a' END, 1, 2) FROM B", true);
TestUtils.assertSqlCanBeParsedAndDeparsed(
"SELECT POSITION(CASE WHEN x IN (1, 2) THEN 'a' END IN y) FROM B", true);
}
}
Loading