ClickHouse / ClickHouse/clickhouse-rs

?fields should support fully-qualifying

Open
#285 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
559
Forks
172
Avg merge
1d 19h
Merged PRs (30d)
3

Description

### Use case

Using `?fields` with joins doesn't work if the same column name (e.g., `id`) occurs in multiple tables, because `?fields` expands to non-qualified names, so the query fails with `ambiguous identifier 'id'`

```rust
client.query("SELECT ?fields FROM table1 JOIN table2 ON table1.foo = table2.bar")
.fetch_all()
.await?;

### Describe the solution you'd like

some kind of API to tell clickhouse how to fully-qualify `?fields`. Maybe something like

```
client.query("SELECT ?fields ...")
.with_fields_qualified_by("table1")
.fetch_all()
```

### Describe the alternatives you've considered

For now I'm just writing out the fields by hand by reading `Self::COLUMN_NAMES` in a loop, but because none of the clickhouse escaping functions are public this is kind of unsafe and dumb

### Additional context

Contributor guide

Open the contributing guide

Research direction

Start at the implementation of the `?fields` expansion and the query-builder API, then inspect how `Self::COLUMN_NAMES` and ClickHouse escaping are currently handled. Define the qualification API and verify it produces valid queries when joined tables share column names, without requiring callers to write fields manually.

Written by the indexing model from the issue text.

Assessment

Tech stack
clickhouse, rust
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.