Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ columnAliases
cteUnboundCol
: (literal AS identifier) # CteUnboundColLiteral
| (QUERY AS identifier) # CteUnboundColParam
| LPAREN columnExpr RPAREN AS identifier # CteUnboundColExpr
| LPAREN? columnExpr RPAREN? AS identifier # CteUnboundColExpr
| LPAREN ctes? selectStmt RPAREN AS identifier # CteUnboundNestedSelect
;

Expand Down Expand Up @@ -1237,6 +1237,7 @@ keywordForAlias
| CURRENT
| INDEX
| TABLES
| TABLE
| TEST
| VIEW
| PRIMARY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void setHasErrors(boolean hasErrors) {
public void enterQueryStmt(ClickHouseParser.QueryStmtContext ctx) {
ClickHouseParser.QueryContext qCtx = ctx.query();
if (qCtx != null) {
if (qCtx.selectStmt() != null || qCtx.selectUnionStmt() != null || qCtx.showStmt() != null || qCtx.describeStmt() != null) {
if (qCtx.selectStmt() != null || qCtx.selectUnionStmt() != null || qCtx.showStmt() != null || qCtx.describeStmt() != null || qCtx.ctes() != null) {
setHasResultSet(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ public void testCTEStatements(String sql, int args) {
ParsedPreparedStatement stmt = parser.parsePreparedStatement(sql);
Assert.assertFalse(stmt.isHasErrors());
Assert.assertEquals(stmt.getArgCount(), args);
Assert.assertTrue(stmt.isHasResultSet());
}

@DataProvider
Expand All @@ -248,7 +249,10 @@ public static Object[][] testCTEStmtsDP() {
{"with a as (select 1) select * from a; ", 0},
{"(with ? as a select a);", 1},
{"select * from ( with x as ( select 9 ) select * from x );", 0},
{"WITH toDateTime(?) AS target_time SELECT * FROM table", 1}
{"WITH toDateTime(?) AS target_time SELECT * FROM table", 1},
{"WITH toDateTime('2025-08-20 12:34:56') AS target_time SELECT * FROM table", 0},
{"WITH toDate('2025-08-20') as DATE_END, events AS ( SELECT 1 ) SELECT * FROM events", 0},
{"WITH toDate(?) as DATE_END, events AS ( SELECT 1 ) SELECT * FROM events", 1}
};
}

Expand Down Expand Up @@ -326,6 +330,8 @@ public Object[][] testMiscStmtDp() {
{"WITH 'hello' REGEXP 'h' AS result SELECT 1", 0},
{"WITH (select 1) as a, z AS (select 2) SELECT 1", 0},
{"SELECT result FROM test_view(myParam = ?)", 1},
{"WITH toDate('2025-08-20') as DATE_END, events AS ( SELECT 1 ) SELECT * FROM events", 0},
{"select 1 table where 1 = ?", 1}
};
}

Expand Down
Loading