Skip to content

Parse IF NOT EXISTS in ALTER ADD INDEX/PROJECTION/CONSTRAINT - #124

Merged
kyleconroy merged 1 commit into
mainfrom
claude/project-thread-8e2oya
Dec 1, 2026
Merged

kyleconroy merged 1 commit into
mainfrom
claude/project-thread-8e2oya

Conversation

@kyleconroy

Copy link
Copy Markdown
Collaborator

Requested by Kyle · project thread

Summary

ALTER TABLE ... ADD INDEX/PROJECTION/CONSTRAINT IF NOT EXISTS failed to parse because only the COLUMN and STATISTICS branches of the ADD alter command consumed IF NOT EXISTS. This adds a small parseIfNotExists helper (it only consumes IF when followed by NOT EXISTS) and uses it in the index, projection and constraint branches, setting IfNotExists on the command.

Fixes #123

Test Plan

  • New fixture parser/testdata/issue_123_alter_add_if_not_exists with the three statements from the issue plus a control. Its explain*.txt files were generated by ClickHouse 26.8.51.4 via cmd/regenerate-explain and match the output quoted in the issue (25.8).
  • New TestAlterAddIfNotExists asserts the IfNotExists flag, since EXPLAIN AST doesn't show it.
  • Without the parser change, stmt1 to stmt3 of the fixture fail; with it, go test ./parser/... -timeout 30s passes and -check-explain reports no metadata changes.

Generated by Claude Code

Only the COLUMN and STATISTICS branches of ALTER ... ADD consumed
IF NOT EXISTS, so ADD INDEX/PROJECTION/CONSTRAINT IF NOT EXISTS failed
to parse. Add a parseIfNotExists helper and use it in those branches.

Fixes #123

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LuRZ4KB7DMX365Nmn5ksnY
@kyleconroy kyleconroy self-assigned this Dec 1, 2026
@kyleconroy
kyleconroy merged commit 4a53725 into main Dec 1, 2026
1 check passed
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.

ALTER TABLE ... ADD INDEX / ADD PROJECTION / ADD CONSTRAINT IF NOT EXISTS fails to parse

2 participants