Skip to content

Treat whitespace-only primary_key values as unset - #832

Merged
koletzilla merged 2 commits into
mainfrom
clickhouse/primary-key-whitespace
Nov 26, 2026
Merged

koletzilla merged 2 commits into
mainfrom
clickhouse/primary-key-whitespace

Conversation

@koletzilla

@koletzilla koletzilla commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Extraction from #717

Before this, primary_key=' ' or primary_key=['id', ' '] rendered an invalid PRIMARY KEY clause and ClickHouse rejected the CREATE TABLE with a syntax error. Now:

  • primary_key_clause now trims the primary_key config before using it.
  • A string that is only whitespace is treated as unset, like '' and [] already were.
  • For a list, every entry is trimmed, whitespace-only entries are dropped, and a list with nothing left is treated as unset.

The same trimming is already in the v2 copy of the macro, so this keeps the two macro trees aligned.


Note

Low Risk
Narrow DDL macro change with integration tests; trims invalid primary_key configs instead of changing valid ones.

Overview
primary_key_clause now trims string values and drops whitespace-only list entries before building ClickHouse DDL, so configs like primary_key=' ' or primary_key=['id', ' '] no longer emit a bare PRIMARY KEY that fails CREATE TABLE. When nothing valid remains after trimming, the clause is omitted and ClickHouse keeps the sorting key as before—same behavior as empty string or [].

Integration coverage adds three table models (whitespace string, mixed list with blank entries, whitespace-only list) and extends test_primary_key_variants to assert the effective primary key via system.tables. CHANGELOG records the bugfix under Unreleased.

Reviewed by Cursor Bugbot for commit c643f9d. Bugbot is set up for automated code reviews on this repo. Configure here.

@security-ai-gate-reviewer security-ai-gate-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-approved by the AI review gate on c643f9d. Details in the approver's comment on this pull request.

@security-ai-gate-reviewer

Copy link
Copy Markdown

AI review gate — auto-approved

c643f9def451 is approved by security-ai-gate-reviewer[bot], an automated identity, not a human. The approval stands on the required AI review: Cursor Bugbot concluded green on this commit and the AI review gate is SUCCESS (its own comment has the verdict), and the change touches no path that requires a human reviewer. It is bound to this commit: a new push dismisses it and the approver re-evaluates.

History (latest 5 heads, newest first)

  • c643f9def451 approved — green: Cursor Bugbot

@koletzilla
koletzilla requested a review from canbekley November 26, 2026 14:45
@koletzilla
koletzilla merged commit 7a6ecc4 into main Nov 26, 2026
19 checks 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.

2 participants