Skip to content

Support COMMENT before AS SELECT in CREATE MATERIALIZED VIEW#262

Merged
git-hulk merged 2 commits intoAfterShip:masterfrom
sharadgaur:sharad/fix-mv-comment-before-as
Apr 9, 2026
Merged

Support COMMENT before AS SELECT in CREATE MATERIALIZED VIEW#262
git-hulk merged 2 commits intoAfterShip:masterfrom
sharadgaur:sharad/fix-mv-comment-before-as

Conversation

@sharadgaur
Copy link
Copy Markdown
Contributor

Summary

ClickHouse's SHOW CREATE TABLE outputs COMMENT between the column list and AS SELECT for materialized views, but the parser only supported COMMENT after AS SELECT.

Before (fails)

CREATE MATERIALIZED VIEW db.mv TO db.target (a String) COMMENT 'test' AS SELECT a FROM db.src
-- Error: line X:0 <EOF> or ';' was expected, but got: "AS"

After (works)

Both positions are now supported:

  • COMMENT before AS SELECT (SHOW CREATE TABLE format) ✅
  • COMMENT after AS SELECT (documented syntax) ✅
  • No COMMENT

Change

Move the tryParseComment() call before the AS SELECT parsing, with a fallback to also try after AS SELECT if no comment was found before.

All existing tests pass.

Fixes #261

ClickHouse 26.2+ changed SHOW CREATE TABLE output to place COMMENT
before AS SELECT, while 25.x places it after. The parser only
supported COMMENT after AS SELECT, causing parse failures on 26.2+.

Now tries COMMENT in both positions:
- Before AS SELECT (ClickHouse 26.2+ SHOW CREATE TABLE format)
- After AS SELECT (ClickHouse 25.x SHOW CREATE TABLE format)

Fixes AfterShip#261
@sharadgaur sharadgaur force-pushed the sharad/fix-mv-comment-before-as branch from 365c90f to 71bc41d Compare April 8, 2026 15:33
@chatgpt-codex-connector
Copy link
Copy Markdown

💡 Codex Review

name := &Ident{
NamePos: p.last().Pos,
NameEnd: p.last().End,
Name: p.last().String,
}

P2 Badge Preserve quote type for named table-arg identifiers

When building name := &Ident{...} for named parameters, the token’s QuoteType is dropped, so quoted keys are normalized to unquoted output. In cases where quoting is required (for example gcs(`my-key`='x')), String() emits my-key='x', which is not valid round-trip SQL and fails if reparsed because - is treated as an operator. Copy p.last().QuoteType (or parse via parseIdent) when constructing the parameter name.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

…26.2+ format)

Adds test SQL file and golden output/format/beautify files for
CREATE MATERIALIZED VIEW with COMMENT between column list and AS SELECT,
which is the format ClickHouse 26.2+ uses in SHOW CREATE TABLE output.
@git-hulk git-hulk changed the title fix: support COMMENT before AS SELECT in CREATE MATERIALIZED VIEW Support COMMENT before AS SELECT in CREATE MATERIALIZED VIEW Apr 9, 2026
@git-hulk git-hulk merged commit 120ff65 into AfterShip:master Apr 9, 2026
1 check passed
@git-hulk
Copy link
Copy Markdown
Member

git-hulk commented Apr 9, 2026

@sharadgaur Thanks for your improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants