Skip to content

ClickHouse: Parsing error for WITH statement using scalar expressions #2221

@martinmsb

Description

@martinmsb

Describe the bug

The ClickHouseDialect parser fails to parse valid ClickHouse syntax when WITH clause is used declaring scalar expressions.

To Reproduce

use sqlparser::dialect::ClickHouseDialect;
use sqlparser::parser::Parser;

fn main() {
    let sql = r#"
        WITH 42 AS answer
        SELECT answer FROM table
    "#;
    
    let dialect = ClickHouseDialect {};
    let result = Parser::parse_sql(&dialect, sql);
    println!("{:?}", result);
}

Error:
Err(ParserError("Expected: identifier, found: 42 at Line: 2, Column: 14"))

Expected behavior tested in ClickHouse 26.1.2.11

The parser using ClickHouseDialect should accept the clause as ClickHouse does support it:
WITH 42 AS answer SELECT answer FROM table

Additional context

The syntax from the ClickHouse documentation for this clause is: WITH <expression> AS <identifier>
sqlparser version: 0.61

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions