Skip to content

bug: parser fails on CREATE MATERIALIZED VIEW with COMMENT before AS SELECT #261

@sharadgaur

Description

@sharadgaur

Problem

The parser fails when COMMENT appears between the column list and AS SELECT in a CREATE MATERIALIZED VIEW statement. This is the exact format ClickHouse returns from SHOW CREATE TABLE.

Reproducer

-- This FAILS:
CREATE MATERIALIZED VIEW db.mv TO db.target
(
    `a` String,
    `b` Int64
)
COMMENT 'some comment'
AS SELECT a, b FROM db.src
Error: line 6:0 <EOF> or ';' was expected, but got: "AS"

Expected

Should parse successfully. ClickHouse outputs this exact format from SHOW CREATE TABLE for any MV that has a COMMENT set.

Root Cause

In parser_view.go, the parser tries COMMENT only after AS SELECT:

if p.tryConsumeKeywords(KeywordAs) { ... }
comment, err := p.tryParseComment()  // only here, after AS SELECT

But ClickHouse's SHOW CREATE TABLE outputs COMMENT before AS SELECT. The parser sees COMMENT where it expects AS or EOF, and fails.

Fix

Try parsing COMMENT both before and after AS SELECT to handle both the documented syntax and the SHOW CREATE TABLE output format.

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