ClickHouse / ClickHouse/ClickHouse

Update Cannot Update One Column From Another

Open
#86,912 3 comments 0 reactions 0 assignees View on GitHub
comp-sql-syntax unexpected behaviour
Dominant language
C++
Stars
49.9k
Forks
9k
Avg merge
21h 32m
Merged PRs (30d)
515

Description

### Company or project name

ClickHouse, [Sqitch](https://sqitch.org).

### Describe the unexpected behaviour

This `UPDATE` does not work:

```
clickhouse :) update bar set baz = id;

Syntax error: failed at position 24 (end of query):

update bar set baz = id;

Expected one of: token sequence, Dot, token, OR, AND, IS NOT DISTINCT FROM, IS NULL, IS NOT NULL, BETWEEN, NOT BETWEEN, LIKE, ILIKE, NOT LIKE, NOT ILIKE, REGEXP, IN, NOT IN, GLOBAL IN, GLOBAL NOT IN, MOD, DIV, Comma, IN PARTITION, WHERE
```

It's pretty typical to be able to update one column from another. Here's Postgres:

```
david=# select * from bar;
id | baz
----+--------
1 | [null]
2 | [null]
3 | [null]
(3 rows)

david=# update bar set baz = id;
UPDATE 3

david=# select * from bar;
id | baz
----+-----
1 | 1
2 | 2
3 | 3
(3 rows)
```

### Which ClickHouse versions are affected?

25.8.2.29

### How to reproduce

```
create table bar(id int primary key, baz int) ENGINE=MergeTree;
insert into bar values (1), (2), (3);
select * from bar;
update bar set baz = id;
select * from bar;
```

### Expected behavior

Should update one column with the value from another.

### Error message and/or stacktrace

```
Syntax error: failed at position 24 (end of query):

update bar set baz = id;

Expected one of: token sequence, Dot, token, OR, AND, IS NOT DISTINCT FROM, IS NULL, IS NOT NULL, BETWEEN, NOT BETWEEN, LIKE, ILIKE, NOT LIKE, NOT ILIKE, REGEXP, IN, NOT IN, GLOBAL IN, GLOBAL NOT IN, MOD, DIV, Comma, IN PARTITION, WHERE
```

### Additional context

Filing this report since the [UPDATE docs](https://clickhouse.com/docs/sql-reference/statements/update) ask for reports for unexpected issues.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.