pravic commented on code in PR #2024:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/2024#discussion_r2336778959


##########
tests/sqlparser_clickhouse.rs:
##########
@@ -1729,6 +1729,65 @@ fn test_parse_not_null_in_column_options() {
     );
 }
 
+#[test]
+fn parse_cse() {
+    clickhouse().verified_stmt("WITH x AS (SELECT 1) UPDATE t SET bar = 
(SELECT * FROM x)");
+
+    let with = concat!(
+        "WITH",
+        " toIntervalSecond(300) AS bucket_size,",
+        " toDateTime64(1735751460, 9) AS start_time,",
+        " toDateTime64(1735755060, 9) AS end_time ",
+        "SELECT",
+        " toStartOfInterval(EventTime, bucket_size) AS bucket,",
+        " count() AS count ",
+        "FROM logs",
+    );
+    clickhouse().verified_query(with);
+
+    let mixed = concat!(
+        "WITH",
+        " toDate(now()) AS today,",
+        " tbl (c) AS (SELECT toDate('2000-01-01')) ",
+        "SELECT",
+        " * ",
+        "FROM tbl ",
+        "WHERE c < today"
+    );
+    clickhouse().verified_query(mixed);
+
+    // valid
+    clickhouse()
+        .parse_sql_statements("WITH foo() AS bar SELECT 1")
+        .unwrap();
+
+    // ClickHouse allows these, but not sqlparser
+    clickhouse()
+        .parse_sql_statements("WITH foo, bar SELECT 1")
+        .expect_err("Expected: AS, found: ,");
+
+    clickhouse()
+        .parse_sql_statements("WITH foo(), bar SELECT 1")
+        .expect_err("Expected: identifier, found: )");

Review Comment:
   Interesting: 
https://fiddle.clickhouse.com/1292850a-31e4-49c7-a309-79bc47a273a2
   
   I am not sure whether it's a feature or a bug in the ClickHouse syntax 
parser. But since these examples don't make much sense, let's leave them as 
rejected.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to