Skip to content

Commit e2757d6

Browse files
fix: ignore IN and FROM inside CASE when detecting named-parameter string functions (#2940)
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 3515208 commit e2757d6

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5723,11 +5723,19 @@ public class CCJSqlParser extends AbstractJSqlParser<CCJSqlParser> {
57235723
*/
57245724
protected boolean isNamedExprListAhead() {
57255725
int depth = 0;
5726+
// IN, FROM inside CASE ... END belong to the CASE branches, not to the function
5727+
int caseDepth = 0;
57265728
for (Token t = getToken(1); ; t = nextWithItemToken(t)) {
57275729
if (t.kind == EOF) {
57285730
return false;
57295731
}
5730-
if (t.kind == OPENING_BRACKET) {
5732+
if (t.kind == K_CASE) {
5733+
caseDepth++;
5734+
} else if (t.kind == K_END && caseDepth > 0) {
5735+
caseDepth--;
5736+
} else if (caseDepth > 0) {
5737+
continue;
5738+
} else if (t.kind == OPENING_BRACKET) {
57315739
depth++;
57325740
} else if (t.kind == CLOSING_BRACKET) {
57335741
if (depth == 0) {

‎src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6773,4 +6773,12 @@ void testSnowflakeCastsAndLateralFlattenRegression() throws Exception {
67736773
TestUtils.assertSqlCanBeParsedAndDeparsed(
67746774
"SELECT user.value FROM t, LATERAL FLATTEN(input => t.data:users) user", true);
67756775
}
6776+
6777+
@Test
6778+
void testStringFunctionWithInPredicateInsideCase() throws JSQLParserException {
6779+
TestUtils.assertSqlCanBeParsedAndDeparsed(
6780+
"SELECT SUBSTR(CASE WHEN x IN (1, 2) THEN 'a' END, 1, 2) FROM B", true);
6781+
TestUtils.assertSqlCanBeParsedAndDeparsed(
6782+
"SELECT POSITION(CASE WHEN x IN (1, 2) THEN 'a' END IN y) FROM B", true);
6783+
}
67766784
}

0 commit comments

Comments
 (0)