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.
Problem
The parser fails when
COMMENTappears between the column list andAS SELECTin aCREATE MATERIALIZED VIEWstatement. This is the exact format ClickHouse returns fromSHOW CREATE TABLE.Reproducer
Expected
Should parse successfully. ClickHouse outputs this exact format from
SHOW CREATE TABLEfor any MV that has a COMMENT set.Root Cause
In
parser_view.go, the parser triesCOMMENTonly afterAS SELECT:But ClickHouse's
SHOW CREATE TABLEoutputsCOMMENTbeforeAS SELECT. The parser seesCOMMENTwhere it expectsASor EOF, and fails.Fix
Try parsing
COMMENTboth before and afterAS SELECTto handle both the documented syntax and theSHOW CREATE TABLEoutput format.